Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

parse ' ' and ',' to make names

parse firstname lastname by ' '(space)
 
$name="Peter L. Panda";

$temp=explode(" ",$name,2);
$firstname=$temp[0]; //==Peter
$lastname=$temp[1]; //==L. Panda


but if name contains a ',' (comma)

last_name,first_name  where last_name is the first word

smith, john
first=john
last=smith

jones, john L
first=john L
last=jones

evans, mary lee
first= mary lee
last=evans
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Interesting problem.  In the first example, the $lastname will not be L. Panda.

I'll see if I can come up with an example that will be useful.  Are you certain that you do not want to account for middle names?
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Apologies -- I spoke before testing.  In the first example, the value of $temp[1] will, in fact, be L. Panda.  I overlooked the limit integer in the call to the explode() function.
Avatar of rgb192

ASKER

works for , and ' ' thanks
Thanks for the points! ~Ray