?
Solved

Finding the position (strpos?) of uppercase character

Posted on 2005-03-31
4
Medium Priority
?
532 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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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

777 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