2013-08-04 151 views
-2

我試圖使用preg_match在字符串中獲取單詞數組.. WORD1WORD2是可以更改的變量。Preg_match找到一個單詞之後的單詞和另一個單詞

$content= 'class="gametitle WORD1">< ggg class="userid">WORD2 </ gg>'; 

我想WORD1WORD2

現在我只是在能夠得到字1

$prematch=preg_match('/.class="gametitle.(.*)".*/isU', $content, $matches); 

echo $matches[1]; 

THX提前!

+1

請解決您的問題描述上面:' 「類=」 gametitle WORD1" > WORD2「'肯定不是一個有效的字符串定義... – arkascha

回答

0
if (preg_match_all('/class\s?=\s?"gametitle\s+(\w+)"><[^>]+>\s?(\w+)/', $text, $matches)){ 
    $word1 = $matches[1][0]; 
    $word2 = $matches[2][0]; 
} 

或者與preg_match

if (preg_match('/class\s?=\s?"gametitle\s+(\w+)"><[^>]+>\s?(\w+)/', $text, $matches)){ 
    $word1 = $matches[1]; 
    $word2 = $matches[2]; 
} 
+0

THX但其不工作..沒有得到anyword ..我會嘗試解釋清楚...我想要在課後=「gametitle和課後=」userid – user2650076

+0

OK。在你原來的問題中,你沒有那個。 –

+0

是啊對不起,我不知道它會去除標籤 – user2650076

相關問題