Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortening full name down so Surname is only first letter

Tags:

string

php

trim

After having read a few questions already asked and checking a few other sites I'm still no further forward in finding a simple way to take a full name like say "Jake Whiteman" and trimming it down so that it would be shown on the web page as "Jake W." obviously without the speech marks round it just so there isn't any confusion there.

Anyone have any idea how to do it? I'm sure its probably just a matter of finding the white space and then trimming down the surname, I just can't seem to find a way of doing it.

Thanks in advance!

like image 855
Geordie Dave Avatar asked Dec 05 '22 15:12

Geordie Dave


1 Answers

$names = explode( " ", $name );
echo $names[0]." ".$names[1][0];
like image 175
sean Avatar answered Dec 07 '22 03:12

sean