PHP parsing HTML class –php simple HTML DOM parser_php tutorial

Source: Internet
Author: User




< span="">Simplehtmldom_1_5

Create DOM from URL or file$html = file_get_html (' http://www.google.com/');//Find All images foreach ($html->find (' I MG ') 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 Htmlecho file_get_html (' http://www.google.com/')->plaintext;

  

Create DOM from url$html = file_get_html (' http://slashdot.org/');//Find All article Blocksforeach ($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);

  

http://www.bkjia.com/PHPjc/440130.html www.bkjia.com true http://www.bkjia.com/PHPjc/440130.html techarticle simplehtmldom_1_5//Create DOM from URL or file$html = file_get_html (' http://www.google.com/'),//Find all images for Each ($html-find (' img ') as $element) echo $element-src. ' BR ';

  • 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.