In php, how to remove all special characters, uppercase letters, numbers and spaces

This is what I still have, but I can’t figure out how to remove it correctly. Any ideas?

preg_replace('[az]', "", strtolower($_GET["myvar"])); 
+1
source share
2 answers

I assume that you are trying to delete everything except lowercase letters. If so, try the following:

 preg_replace('/[^az]/', "", strtolower($_GET["myvar"])); 

This converts $_GET["myvar"] to all lowercase letters, and then removes everything that is not a lowercase letter.

+8
source
 preg_replace('/[^az]/', '', strtolower($_GET['myvar'])); 

technically, there could never have been any uppercase letters, since you guarantee that all letters will be lowercase before the regular expression ever gets into the string. In any case, this regular expression will remove anything that is NOT-z.

You almost had this, and just had no inversion ( ^ ) and no separators ( // ).

+3
source

All Articles