【发布时间】:2011-07-06 21:46:28
【问题描述】:
我有一个注册表单,提交时会向我们发送一封电子邮件。我可以修剪建议的用户名字段以防止输入多个单词吗?或者也许在提交时自动消除空格以形成一个单词?
【问题讨论】:
我有一个注册表单,提交时会向我们发送一封电子邮件。我可以修剪建议的用户名字段以防止输入多个单词吗?或者也许在提交时自动消除空格以形成一个单词?
【问题讨论】:
您应该查看preg_replace($patterns, $replacements, $string); 在您的情况下,您会想要:
// \s+ means 1 or more whitespace characters.
// '' means that the whitespace will be replaced by emptiness.
// so this should return a string which replaces all whitespace with nothing
preg_replace("#\s+#g", '', $string);
【讨论】: