[英]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.这会将
$_GET["myvar"]
转换为所有小写字母,然后删除任何不是小写字母的内容。
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.
在任何情况下,这个正则表达式都会删除任何 ISN'T az。
You almost had it, and were just missing the inversion ( ^
) and the delimiters ( //
).您几乎拥有它,只是缺少反转(
^
)和分隔符( //
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.