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 ( // ).
source share