Allow only [a-z][A-Z][0-9] in string using PHP

前端 未结 6 1530
栀梦
栀梦 2020-11-28 14:38

How can I get a string that only contains a to z, A to Z, 0 to 9 and some symbols?

6条回答
  •  旧巷少年郎
    2020-11-28 15:19

    Both these regexes should do it:

    $str = preg_replace('~[^a-z0-9]+~i', '', $str);
    

    Or:

    $str = preg_replace('~[^a-zA-Z0-9]+~', '', $str);
    

提交回复
热议问题