Jump to content

Question about Simple DOM parser


boneXXX

Recommended Posts

hi all,

 

I am trying to figure out how simple DOM parser works. If someone can explain these example code, I would really appreciate it.

 

<?php
include_once('./simple_html_dom.php');

// 1. Write a function with parameter "$element"
function my_callback($element) {


    if ($element->tag=='h1')
        $element->innertext = 'h1';



    if ($element->tag=='h1')
        $element->outertext = 'h1';
        

    if ($element->tag=='img')
        $element->outertext = 'img';

    if ($element->tag=='a')
     
  $element->outertext = 'a';
}

// 2. Create DOM from URL
$html = file_get_html('http://www.example.com/');

// 3. Register the callback function with it's function name
$html->set_callback('my_callback');

// 4. Callback function will be invoked while dumping
echo $html;
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/128134-question-about-simple-dom-parser/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.