简体   繁体   中英

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

This is what i've got so far, but i cant seem to figure out the proper way to have it remove spaces. Any ideas?

preg_replace('[a-z]', "", strtolower($_GET["myvar"]));

I'm guessing you are trying to remove everything except lowercase letters. If that is the case, try this:

preg_replace('/[^a-z]/', "", strtolower($_GET["myvar"]));

This is will transform $_GET["myvar"] to all lowercase letters then remove anything that isn't a lowercase letter.

preg_replace('/[^a-z]/', '', strtolower($_GET['myvar']));

technically, there couldn't ever be any upper case letters, since you're guaranteeing that all letters will be lower case before the regex ever gets its hands on the string. In any case, this regex will remove anything that ISN'T az.

You almost had it, and were just missing the inversion ( ^ ) and the delimiters ( // ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM