[英]preg_replace to remove all characters except dashes, letters, numbers, spaces, and underscores
我需要删除字符串中除破折号,字母,数字,空格和下划线以外的所有字符。
SO上的各种答案都非常接近( 替换字母,数字,空格和下划线 以外的所有字符 , 删除字母,空格和撇号等以外的所有字符 ),但通常不包括破折号。
帮助将不胜感激。
您可能需要类似:
$new = preg_replace('/[^ \w-]/', '', $old);
说明 :
[^ \w-]
Match any single character NOT present in the list below «[^ \w-]»
The literal character “ ” « »
A “word character” (Unicode; any letter or ideograph, any number, underscore) «\w»
The literal character “-” «-»
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.