PHP:获取包含特定文本的所有行

时间:2011-02-09 02:27:39

标签: php

我正在尝试从类似

的网站解析源代码
   <html>
    ...
    ...
    ...
    <div class="menu_body">
    <a href="url" onclick="_gaq.push([parameters]);location.href=this.href+'?channelId=287&date='+dateOfMonth;return false;"> <img src="img"></a>
    <a href="url"><img src="img"></a>
    <a href="url"><img src="img"></a>
    </div>
    ...
    ...
    <div class="menu_body">
    <a href="url"><img src="img></a>
    <a href="url"><img src="img"></a>
    <a href="url"><img src="img"></a>
    </div>
    ...
    ...
    ...
    </html>

如果可能的话,我想要做的只是查看包含channelId的所有行,不确定是否可能?

2 个答案:

答案 0 :(得分:0)

听起来你想要某种HTML Parser

http://simplehtmldom.sourceforge.net/    <-- PHP
http://htmlparser.sourceforge.net/         <--- Java

/ ** @see Robust and Mature HTML Parser for PHP * /

答案 1 :(得分:0)

使用CURL或file_get_contents将html作为字符串读取,然后使用 的preg_match。 http://php.net/manual/en/function.preg-match.php

相关问题