简体   繁体   English

在 php 如何删除所有特殊字符、大写字母、数字和空格

[英]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.

相关问题 替换字母,数字和空格以外的所有字符 - Replace all characters except letters, numbers and spaces 如何删除所有特殊字符和空格,但逗号(,),冒号(:),双引号(“)和字符串的花括号除外 - How to remove all special characters and spaces except Comma(,), Colon(:),Double quote(") and curly braces of a string PHP 如何使用PHP删除文本字段上的特殊字符和空格 - How to I remove special characters and spaces on a textfield using PHP preg_replace删除除破折号,字母,数字,空格和下划线以外的所有字符 - preg_replace to remove all characters except dashes, letters, numbers, spaces, and underscores PHP preg_match 仅用于数字和字母,无特殊字符 - PHP preg_match for only numbers and letters, no special characters 如何在PHP中删除特殊字符 - How to remove the special characters in PHP 如何在PHP中删除特殊字符 - How to remove special characters in php PHP函数/脚本,用于合并数据库中的2列并删除其特殊字符和空格 - php function/script for combining 2 columns in a database and remove their special characters and spaces 我试图删除特殊字符,但保留空格和_不工作PHP - I am trying to remove special characters but keep spaces and _ not working PHP 如何在PHP中对带有特殊字符或数字的数组进行排序? - How to sort array with special characters or numbers in PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM