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:
[/code]
HellothisisaSENTENCE
[/code]
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));