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:
split() function is deprecated in PHP > 5.3
true and agree with you
@Chriss, better to update it
thanks
Thanks Orves for this suggestion.
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
Now time is for using explode() function :).
Easy just do this:
easy!!!
To split the whol full name into first name, middle name and last name.
$name = “Mike Mad Smith”;
list($fname,$mname, $lname) = split(‘ ‘, $name,3);
echo “First Name: $fname, Middle Name: $mname, Last Name: $lname”;
$name = explode(“ ”, “Mike Mad Smith”);
$fname = $name[0]
$lname = end($name);
echo “First Name: $fname, Last Name: $lname”;
What if it’s…
All these methods will have
'Jr.'
as the last name because they assume the last index is the last name, no?Hi
I want to Split the Name ADHITHI C ANEESH as First name and sur name…please help me