当前位置:Gxlcms > PHP教程 > PHP解析HTML类–PHPSimpleHTMLDOMParser_PHP教程

PHP解析HTML类–PHPSimpleHTMLDOMParser_PHP教程

时间:2021-07-01 10:21:17 帮助过:23人阅读





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 . '
'; // Find all links foreach($html->find('a') as $element) echo $element->href . '
';

// Create DOM from string
$html = str_get_html('HelloWorld');

$html->find('div', 1)->class = 'bar';

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

echo $html; // Output: fooWorld

  

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

  

// 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);

  

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';/...

人气教程排行