如何在 PHP 中的空格后删除所有内容? [英] How do I remove everything after a space in PHP?
本文介绍了如何在 PHP 中的空格后删除所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个有名字的数据库,我想在名字上的空格后使用 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";
我想让它回来
Laura
John.
John
推荐答案
这样做,这会替换空格字符之后的任何内容.也可以用于破折号:
Do this, this replaces anything after the space character. Can be used for dashes too:
$str=substr($str, 0, strrpos($str, ' '));
这篇关于如何在 PHP 中的空格后删除所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文