2012-03-30 131 views
-1

可能重複:
preg_replace all but numbers, letters, periods, and slash?PHP的preg_replace(從字符串替換除了字母,數字,和幾個字符的所有字符)

我有一個字符串,我想從字符串替換所有字符除外:

  • 所有字母字母
  • 所有數字
  • @
  • ;
+1

修改鏈接的答案包括fe你想用其中的'[]' – 2012-03-30 17:04:28

+0

'來替換其他字符嗎?或者你想刪除? – 2012-03-30 17:04:42

+0

我要刪除 – CBuzatu 2012-03-30 17:06:02

回答

4

簡單Preg_Replace與空字符串unicode的屬性:

preg_replace('/[^\[email protected],.;]/', '', $string); 

[^] represents a list of characters NOT to match 
\w Word character (abcABC0-9_) 
,.; as the characters themselves 
+1

'\ w'表示'[a-zA-Z0-9_]' – Toto 2012-03-30 17:11:44

+0

非常感謝您對\ w和\ d的描述,這對我來說非常有用! – CBuzatu 2012-03-30 17:19:38

2

關於如何:
\pN

preg_replace('/[^\pL\[email protected],.;]+/', '', $string); 

\pL是字母的unicode屬性是數字

相關問題