Stripping everything but alphanumeric chars from a string in PHP

后端 未结 5 2054
花落未央
花落未央 2020-12-08 19:08

I\'d like a regexp or other string which can replace everything except alphanumeric chars (a-z and 0-9) from a string. All things such as ,@#

5条回答
  •  时光说笑
    2020-12-08 19:32

    I like using [^[:alnum:]] for this, less room for error.

    preg_replace('/[^[:alnum:]]/', '', "(ABC)-[123]"); // returns 'ABC123'
    

提交回复
热议问题