[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Finding the position (strpos?) of uppercase character

Posted on 2005-03-31
4
Medium Priority
?
542 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 look for a specific file type in a local or remote server directory using PHP.

649 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