AlphaApp AlphaApp - 1 year ago 103
PHP Question

How do I remove everything after a space in PHP?

I have a database that has names and I want to use PHP replace after the space on names, data example:

$x="Laura Smith";
$y="John. Smith"
$z="John Doe";


I want it to return

Laura
John.
John

Answer Source

Do this, this replaces anything after the space character. Can be used for dashes too:

$str=substr($str, 0, strrpos($str, ' '));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download