Remove Non-Alphanumeric Characters from a String in PHP
Remove all non-alphanumeric characters from a string, which aren’t in a-zA-Z0-9
range or which are not spaces:
preg_replace('/[^A-Za-z0-9 ]/i', '', $string); |
If you want to support unicode characters:
preg_replace('/[^[:alnum:][:space:]]/u', '', $string); |
More Related Posts
- [2016/05/19] Check if a String Contains Multiple Wo...
- [2016/06/04] Check if a Number is Multiple of Anoth...
- [2016/06/07] How to Get File Extension in PHP
- [2016/05/20] Turn Off Expose_PHP (Hide X-Powered-By...
- [2016/05/26] How to Increase PHP Memory Limit
- [2016/05/25] Disable PHP Notice: Undefined variable...
- [2016/05/27] PHP Domain Parser: Domain\URL Parser P...
- [2016/05/19] Validate Value as Integer in PHP