2014-01-16 39 views
2

我想更改我的字符串中的所有特殊字符,但我想保留所有重音字符。是否可以使用preg_replace()如何更换所有特殊字符,但保留口音

我当前的代码:

preg_replace('/[^A-Za-z0-9\-]/', '', $string); 
+2

你好Riskesh,这个话题是不一样的你的话题。 :) – Dimitri

+0

** @ Closevoters:**上面提供的副本不是正确的。 – HamZa

回答

5

尝试的Unicode:

preg_replace('/[^\p{L}0-9\-]/u', '', $string); 

\p{L}Unicode property匹配所有字母的任何语言,Unicode properties on php.net

+0

Hey stema!感谢您的回复!这很好!如果我不想取代&和单引号,我该怎么做? – Dimitri

+0

对于这个问题,PHP的文档似乎更准确:http://www.php.net/manual/en/regexp.reference.unicode.php –

+0

感谢大家的帮助! – Dimitri

相关问题