我想删除特殊符号、句点、连字符、下划线和;字符串中的数字-PHP

我想删除特殊符号、句点、连字符、下划线和;字符串中的数字-PHP,php,regex,string,preg-replace,Php,Regex,String,Preg Replace,我的要求是删除字符串中除下划线以外的所有特殊符号 我在用 $string = 'text-text_text+text@text(text)text&text.text*text\text/text'; $columnName = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '_', $string); 输出: text-text_text_text_text(text)text&text.text_text_text

我的要求是删除字符串中除下划线以外的所有特殊符号

我在用

$string = 'text-text_text+text@text(text)text&text.text*text\text/text';
$columnName = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '_', $string);
输出:

text-text_text_text_text(text)text&text.text_text_text_text
但它并没有删除句号、符号、括号和破折号。创建这个正则表达式时,我感到无助。请帮助..

尝试:

$string = 'text-text_text+text@text(text)text&text.text*text\text/text';
$columnName = preg_replace('/[-`~!@#$%\^&*()+={}[\]\\\\|;:\'",.><?\/]/', '_', $string);
尝试:


如果要删除除字母、数字和下划线以外的所有字符,只需使用

preg_替换('/[^a-zA-Z0-9]/',''.',$string)

PREG
函数中,类似
[^…
的表达式意味着您希望保留以下所有字符(因此您的表达式不会(!)删除符号和括号a.s.o


顺便说一句:我在表达式中使用下划线,因为它将再次被下划线替换,所以当您要删除除字母、数字和下划线以外的所有字符时,无需在正则表达式中列出它

preg_replace('/[^a-zA-Z0-9]/','.'',$string);

PREG
函数中,类似
[^…
的表达式意味着您希望保留以下所有字符(因此您的表达式不会(!)删除符号和括号a.s.o


顺便说一句:我在表达式中使用下划线,因为它将再次被下划线替换,因此无需在正则表达式中列出它。

preg\u replace('/[^a-zA-Z0-9]/','.'''',$string);
hey thanx..它起作用了..添加它作为一个答案,然后标记它是否正确。
preg\u replace('/[^a-zA-Z0-9]/','.$string)
hey thanx..成功了..添加它作为答案,我会将其标记为正确。
text_text_text_text_text_text_text_text_text_text_text_text