因此,"没有任何"(忽略双引号)将变为" There_wouldnt_be_any ".我对reg表达式毫无用处,因此在帖子中.欢呼解决方案 $newstr = preg_replace('/[^a-zA-Z0-9\']/', '_', "There wouldn't be any");$newstr = str_replace("'", '', $newstr);我将它们放在两行中,以使代码更加清晰.注意:如果您正在寻找Unicode支持,请参阅下面的Filip答案.除了A-z以外,它将匹配所有注册为字母的字符.I am wanting to replace all non letter and number characters i.e. /&%#$ etc with an underscore (_) and replace all ' (single quotes) with ""blank (so no underscore).So "There wouldn't be any" (ignore the double quotes) would become "There_wouldnt_be_any".I am useless at reg expressions hence the post.Cheers 解决方案 $newstr = preg_replace('/[^a-zA-Z0-9\']/', '_', "There wouldn't be any");$newstr = str_replace("'", '', $newstr);I put them on two separate lines to make the code a little more clear.Note: If you're looking for Unicode support, see Filip's answer below. It will match all characters that register as letters in addition to A-z. 这篇关于PHP preg_replace特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 05-27 06:47