想分析网页?不会写正则?这。。。一切都不是问题

在以前是不可想象的。但如今google的项目里有这个phpQuery,它可以让一切变得可能。。。

phpQuery is a server-side, chainable, CSS3 selector driven Document Object Model (DOM) API based on jQuery JavaScript Library.

Library is written in PHP5 and provides additional Command Line Interface (CLI).

如果你使用过jQuery,你会发现这一切是如此的相象。

<?php

include_once( './phpQuery.php' );

$html = new phpQueryDocumentFile('xxx.html');
$title = $html->find('title')->text();

echo $title;
以上内容是取得网页的 title。多方便啊。。。

如果是取得某个class的内容呢?

<?php

//...include
//...new phpQueryDocument

$html->find('div.test eq(1)')->html();
//表示取得div的class为test的,第一个匹配的元素中html内容
呵呵,快去:http://code.google.com/p/phpquery/下载吧