Separate First and Last Name
$name = "John S Smith";
list($fname, $lname) = split(' ', $name,2);
echo "First Name: $fname, Last Name: $lname";
Works with or without middle name.
$name = "John S Smith";
list($fname, $lname) = split(' ', $name,2);
echo "First Name: $fname, Last Name: $lname";
Works with or without middle name.
split() function is deprecated in PHP > 5.3
true and agree with you
@Chriss, better to update it
thanks
Or maybe something more like this to literally get their first and last name, no matter how much junk they enter
Perhaps a better way to go would be to strip multiple whitespace from the name before exploding it.
Like this:
list($fname,$lname) = explode(‘ ‘, str_replace(‘/\s+/gi’,’ ‘,$name), 2);
Note that with the limit in place, $lname always ends up with the middle names and/or initials. Also, to make this accurate with the limit param in place, you need to ensure that there are no extra spaces. preg_split with a look ahead assertion can solve these two issues with one line of code still:
Hi, help me to split my name IMMANUELPRABHU JOSHUA into First name, Middle name & Surname
Regards
Immanuel.J