2010-07-15 52 views
1

如何從本文中獲得WORD和WORD2。php,從文本中獲取一些代碼

text tex asad t text [mycode]WORD[/mycode] tex asda [mycode]WORD2[/mycode] asdasdasd 

我嘗試用預浸匹配,但我失敗

+1

你有什麼這麼遠嗎? – Artefacto 2010-07-15 08:03:01

+0

Artefacto的意思是:發佈失敗的代碼。 – Anax 2010-07-15 08:03:38

回答

4
$str = "text tex asad t text [mycode]WORD[/mycode] tex asda [mycode]WORD2[/mycode] asdasdasd"; 
preg_match_all("/\[mycode\](.*?)\[\/mycode\]/", $str, $preg); 
print_r($preg); 
+0

之前幾秒鐘:) – 2010-07-15 08:08:01

+1

我不知道爲什麼每個人都堅持以正斜槓開始和結束正則表達式.....如果你使用了不同的東西,你不必逃避它! – mpen 2010-07-15 08:09:46