Phpquery PHP collection and HTML processing classes

Source: Internet
Author: User
Tags php server

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/

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.