One line PHP code to remove characters except numbers and letters



I found this few lines of PHP script useful to sanitize user input, it removes characters except numbers and letters:

$clean_code = preg_replace('/[^\w]/', '', $string);

Or this one:

$clean_code = preg_replace('/[^a-zA-Z0-9]/', '', $string);

Original post is here: https://coderwall.com/p/bn47ka/remove-all-characters-except-letters-and-numbers-in-php

loading...

Leave a Reply

Your email address will not be published. Required fields are marked *