AlphaApp AlphaApp - 5 months ago 47
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


Answer Source

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

$str=substr($str, 0, strrpos($str, ' '));