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