2012-03-16 125 views
2

我有這樣的表達:如何使用preg_split()刪除方括號?

The Exorcist's [Restored Version] (xvid110-sickboy88) 

而想輸出是這樣的:

The Exorcist's Restored Version xvid110 sickboy88 

請幫助在此先感謝。

+0

我不認爲'preg_split()'是這種方式... – 2012-03-16 16:43:05

+0

當然,你需要刪除所有的括號是$ string = str_replace(array('[',']', '(' ')'), '',$字符串); – 2012-03-16 16:43:20

回答

6

不需要正則表達式。 str_replace()將完成這項工作。如果它的第一個參數是一個數組,但第二個參數是一個字符串,則第一個數組的所有元素將被第二個字符串參數替換。

$input = "The Exorcist's [Restored Version] (xvid110-sickboy88)"; 
$str = str_replace(array("[", "]", "(", ")"), "", $input); 
echo $str; 

// The Exorcist's Restored Version xvid110-sickboy88 
+2

+1。適合正確工作的正確工具。因爲在其中一個房間裏有蒼蠅,所以不需要對建築物進行核武器。 – 2012-03-16 16:45:51

2
 $string = "The Exorcist's [Restored Version] (xvid110-sickboy88)"; 
     $simbols = array("[", "]", "(", ")"); 
     echo str_replace($simbols , "", $string); 
0

* 嘗試這是工作........ 中間鄉紳括號前使用正斜槓*

$關鍵字=使preg_split(「/ [[]]/「,」[超文本]語言,編程「);

print_r($ keywords);