PHP获取包含单词的div

时间:2013-08-13 19:06:30

标签: php preg-match preg-match-all

我正在尝试在本页底部http://mpgh.net/forum/175-crossfire-hacks-cheats/获取包含[发布]的div。

<?php
$text = file_get_contents("http://mpgh.net/forum/175-crossfire-hacks-cheats/");

$check_hash = preg_match('#<div class=\"inner\"> <h3 class=\"threadtitle\"> <a href="\.*?\" id=\".*?\"><img class=\".*?\" src=\".*?\" alt=\"Go to first new post\" title=\"Go to first new post\"></a> <img src=\".*?\" alt=\".*?\" border=\"0\" title=\".*?\"> <span class=\"prefix understate\"> <span style=\".*?\"><b>(.*?)</b></span> </span> <a class=\"title threadtitle_unread\" href=\"(.*?)\" id=\".*?\">(.*?)</a> </h3> <div class=\"threadmeta\"> <div class=\"author\"> <span class=\"label\">Started by&nbsp;<a rel=\"nofollow\" href=\"(.*?)\" class=\"username understate\" title=\"Started by (.*?) on .*?\">.*?</a>.*?</span> </div> </div> </div>#', $text, $match);

print_r($match);

我尝试了这个但它不起作用,现在我很困惑,因为我找不到解决方案。

感谢。

1 个答案:

答案 0 :(得分:0)

使用simple html dom
试试这段代码:

require_once('simple_html_dom.php');
$html = file_get_html('http://mpgh.net/forum/175-crossfire-hacks-cheats/');
$ret = $html->find('div[class=inner]',0);
echo $ret->innertext;