PHP parsing HTML class – PHP Simple HTML DOM Parser_PHP tutorial

WBOY
Release: 2016-07-20 11:16:15
Original
920 people have browsed it





 

simplehtmldom_1_5

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

// Find all images 
foreach($html->find('img') as $element) 
       echo $element->src . '<br>';

// Find all links 
foreach($html->find('a') as $element) 
       echo $element->href . '<br>';
Copy after login

 

// Create DOM from 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>
Copy after login

  

// Dump contents (without tags) from HTML
echo file_get_html('http://www.google.com/')->plaintext;
Copy after login

  

 

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

// Find all article blocks
foreach($html->find('div.article') as $article) {
    $item['title']     = $article->find('div.title', 0)->plaintext;
    $item['intro']    = $article->find('div.intro', 0)->plaintext;
    $item['details'] = $article->find('div.details', 0)->plaintext;
    $articles[] = $item;
}

print_r($articles);
Copy after login

  

 

 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440130.htmlTechArticlesimplehtmldom_1_5 // Create DOM from URL or file$html = file_get_html('http://www.google.com/');// Find all images foreach($html-find('img') as $element) echo $element-src . 'br';/...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template