I. Introduction of Phpquery
We usually use regular expressions to get the part we want when working with data collected or working with HTML documents on the PHP server.
For HTML pages, there are 3 main reasons why you should not use regular
1, writing conditional expressions more trouble
Especially for beginners, see a bunch of "unintelligible" word Fu Yi together, a kind of head to explode the feeling. If the object to be detached is not too obvious, it is more cumbersome to write.
2, the efficiency is not high
For PHP, the regular should be no way, can be solved by the string function, do not bother the regular. Using the regular to deal with a file of more than 30 K, efficiency is not guaranteed.
3, there are phpquery
If you've ever used jquery, it should be easy to get a particular element, Phpquery makes it possible. You can filter the data you want by the jquery syntax selector.
Phpquery is a newly added domdocument based on PHP5. The DOMDocument is specifically designed to handle html/xml. It provides a powerful XPath selector and many other html/xml operation functions, making it easy to handle html/xml.
Second, Phpquery simple and practical
include ' phpquery.php ';
Phpquery::newdocumentfile (' http://www.scutephp.com ');
$companies = PQ (' #hotcoms. COMs ')->find (' div ');
foreach ($companies as $company)
{
Echo PQ ($company)->find (' H3 a ')->text (). "
";
}
?>
Summary
PQ () is like a $ () in jquery
Basically the jquery selector can be used on phpquery, just put '. ' Become '--'
Phpquery provides several ways to load files, some use strings, some use files (including URLs), and choose to pay attention to
Project Address: http://code.google.com/p/phpquery/