Extremely easy PHP HTML DOM parser php simple HTML DOM parser/with Chinese manual

Source: Internet
Author: User

Extremely simple PHP HTML DOM parser PHP Parser, with a Chinese manual, is an extremely useful library for PHP developers who need to parse the structure of the HTML code DOM, using jquery-style DOM nodes to find syntax, Highly recommended.

Here's a quick start, excerpted from the Chinese manual.

Create a DOM object from a URL or file
$html = file_get_html(' http://www.google.cn/');

//looking for all img tags
find (' img ') as $element)
src  . ' <br> ';

//look for all the link tags
find (' a ') as $element)
href  . ' <br> ';

Extract content from HTML (without tags)
echo file_get_html(' http://www.google.com/'),plaintext;

Create a Dom object from a string
$html = str_get_html(' <div id= ' hello ' >hello</div><div id= ' world ' >World</div> ');


$html,find(' div ', 1),class = ' Bar ';

$html,find(' Div[id=hello] ', 0),innertext = ' foo ';

Echo $html; Output: <div id= "Hello" >foo</div><div id= "World" class= "bar">World</div>

Create a DOM object from a URL
$html = file_get_html(' http://slashdot.org/');


Looking for all the article blocks
foreach ($html,Find(' Div.article ') as $article) {
$item [' title '] = $articleFind(' Div.title ', 0)plaintext;
$item [' intro '] = $articleFind(' Div.intro ', 0)plaintext;
$item [' details '] = $articleFind(' Div.details ', 0)plaintext;
$articles [] = $item;
}

Print_r ($articles);

More information

Download http://sourceforge.net/projects/simplehtmldom/

Chinese manual http://phpdom.comsing.com/


This article is from the "Half City" blog, please be sure to keep this source http://vabc1314.blog.51cto.com/2164199/1839213

Extremely easy PHP HTML DOM parser php simple HTML DOM parser/with Chinese manual

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.