Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Finding the position (strpos?) of uppercase character

Posted on 2005-03-31
4
Medium Priority
?
550 Views
Last Modified: 2008-03-03
Hello experts,

I have a string like this:

LastnamelalalaSecondLastNameFirstname

I need separate the Firstname from the rest by checking right-to-left and finding capital F for firstname.

any ideas?

0
Comment
Question by:sow56091
4 Comments
 
LVL 11

Assisted Solution

by:matt_mcswain
matt_mcswain earned 668 total points
ID: 13678676
If you just need to find last occurrence of cap F and remaining string, you can use strrchr()-->http://us3.php.net/manual/en/function.strrchr.php

<?php $string = 'LastnamelalalaSecondLastNameFirstname';
          echo strrchr($string,'F');
?>

Or if you need the position of last cap F, use strrpos()-->http://us3.php.net/manual/en/function.strrpos.php
<?php $string = 'LastnamelalalaSecondLastNameFirstname';
          echo strrpos($string,'F');
?>
0
 
LVL 8

Assisted Solution

by:_Marcel_
_Marcel_ earned 668 total points
ID: 13678731
I think you will need preg_split (http://www.php.net/manual/en/function.preg-split.php) to do this:

$string = 'LastnamelalalaSecondLastNameFirstname';
$temparray = preg_split(/[A-Z]/, $string);
$firstname = array_pop($temparray);
0
 
LVL 3

Accepted Solution

by:
lokip earned 664 total points
ID: 13678830
<?php
preg_match( '!.*([A-Z][a-z]*)$!', $string, $matches );

echo "My first name is " . $matches[1];
?>
0
 
LVL 3

Author Comment

by:sow56091
ID: 13686910
thank you everyone. those were all excellent answers.

Sean
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question