【发布时间】:2017-05-19 15:00:02
【问题描述】:
用户在两个单独的字段中提交姓名: 名字(author_fname)和姓氏(author_lname) 条目有时是 Smith、John J. 或 John and Mary Smith,或 john j。史密斯。 我需要从提交中删除所有无关的字符,所以名称只包含以下单词:smithjohnj 或 johnandmarysmith。 使用修剪,我能够删除空白。
但我也想去掉逗号。例如:
$text = $results["author_lname"].$results["author_fname"];
$trimmed = trim($text);
var_dump($trimmed);
$Aname = $trimmed;
【问题讨论】:
-
trim 只删除字符串开头和结尾的字符,而不是中间的字符。如果没有第二个参数,它只会删除空格。
-
您应该尝试自己编写代码。在doing more research 之后,如果您有问题发布您尝试过的方法,并清楚地解释什么不起作用,并提供a Minimal, Complete, and Verifiable example。阅读How to Ask 一个好问题。请务必take the tour 并阅读this。
-
我就是这么想的。在查看手册时,我看到: string trim ( string $str [, string $character_mask = " \t\n\r\0\x0B" ] ) 所以我的应该是: $text trim ( string $text [, string $character_mask = " ",.])