StoutFiles

msg:4034020 | 2:24 pm on Nov 30, 2009 (gmt 0) |
First letter is easy. echo $full_names[0]; Next question is tricky. Best solution I can think of is to work backwards with a loop reading in the last name characters till you hit a space. Get the character count.. $count = strlen($full_names); Then use this variable in a while loop counting backwards and storing the characters in a variable(backwards) until you hit a space. Once you hit the space you'll have your last name.
|
dreamcatcher

msg:4034033 | 2:46 pm on Nov 30, 2009 (gmt 0) |
Easiest way for last name is to use explode [php.net] $string = 'James Carpenter Robertson'; $name = explode(' ',$string); echo $name[count($name)-1)]; You can also use strrpos [php.net] to get the last occurence of a space. Combine this with substr [php.net] and strlen [php.net]: $string = 'James Carpenter Robertson'; echo substr($string,strrpos($string, ' '),strlen($string)); dc
|
StoutFiles

msg:4034042 | 2:56 pm on Nov 30, 2009 (gmt 0) |
That works too, a lot cleaner and easier.
|
ahmed24

msg:4034048 | 3:05 pm on Nov 30, 2009 (gmt 0) |
strrpos method works perfectly. many thanks for your help dreamcatcher and StoutFiles
|
|