If you need to remove all special characters, grammar, punctuation and spaces from a string in PHP, this nice regular expression (regex) is just what you need.

$string = 'Hello, this is a SENTENCE!!';
$result = preg_replace('/[^a-zA-Z0-9-_\.]/','', $string);

The above would output:


If you wanted to make it all lowercase, you would do the following:

$string = 'Hello, this is a SENTENCE!!';
$result = strtolower(preg_replace('/[^a-zA-Z0-9-_\.]/','', $string));
Free Graphics, Icons, Tutorials
Free Graphics Free Christmas Vector Icon Graphics Pack 2017Free Fitness Vector Icons Graphics PackFree Camping Vector Graphics PackFree Summer Graphics PackFree File Icon PackFree Fast Food Vector Graphics
Sharing is caring...
Like & Follow
Share the love, share this page! Facebook Twitter Digg Reddit LinkedIn Pinterest Email
Close [X]
The Web Taylor
1000 Lakeside North Harbour Portsmouth, Hampshire PO6 3EN
02392 123358