【问题标题】:Prevent multiple words form field PHP MySQL防止多个单词表单字段PHP MySQL
【发布时间】:2011-07-06 21:46:28
【问题描述】:

我有一个注册表单,提交时会向我们发送一封电子邮件。我可以修剪建议的用户名字段以防止输入多个单词吗?或者也许在提交时自动消除空格以形成一个单词?

【问题讨论】:

    标签: php mysql forms


    【解决方案1】:

    您应该查看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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多