php
  • string
  • preg-match
  • 2012-11-13 71 views 1 likes 
    1

    可能重复空间:
    PHP - regex to allow letters and numbers onlyPHP字母,数字,字符串其余

    首先对不起我的英语不好。 我有问题。

    我有一个字符串(这只是一个例子)

    $string = 'on"c,e. //[email protected]#on$# a @#ti'][;me 2012'; 
    

    什么我需要做的,使字符串的样子:

    $string_after_clean_up = 'once upon a time 2012'; 
    

    我需要删除所有的符号,除了字母/数字和空格。 我正在尝试preg_mach(),但我失败了。

    回答

    4

    $string_after_clean_up = preg_replace("/[^a-z0-9\s]/i", "", $string); $string_after_clean_up = preg_replace("/\s\s+/", " ", $string_after_clean_up);

    +0

    我得到错误。 preg_replace():未知修饰符'g' –

    +1

    只使用'i'修饰符,不需要'g'那里 – dakdad

    +0

    愚蠢的我。最近的JavaScript太多了。我编辑了答案。 –

    相关问题