Search code examples
phpstrip

How to get last name first inital


Possible Duplicate:
Regex - Return First and Last Name

Hi,

I have the full name of users stored in one field. How can i get the full first name and last name first initial. This is what i am using right now:

 $first = substr($full_n, 0, strpos($full_n,' '));  

Solution

  • (not an answer but too big to be a comment)

    There is no solution to this problem, you will just have to decide in what way will you mangle peoples names.

    There are several decent examples in the answers already, but they will all fail on Pekka's examples in his comment. Some names like Hillary Rodham Clinton are often hyphenated Hillary Rodham-Clinton and will be less of a problem.

    Simpler common examples such as John von Neumann or Phillip de la Cruz will still fail.