dongyong6045 2011-07-06 21:46
浏览 22

防止多个单词形成字段PHP MySQL

I have a sign-up form that just sends us an email when submitted. Can I trim the suggested username field to prevent multiple words from being entered? Or perhaps automatically eliminate the spaces upon submit to form a single word?

  • 写回答

1条回答 默认 最新

  • dongzhi9457 2011-07-06 21:48
    关注

    You should look into preg_replace($patterns, $replacements, $string); In your case, you would want:

    // \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);
    
    评论

报告相同问题?