2013-08-04 237 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

相关问题