首页 > 代码库 > simple_html_dom(4)

simple_html_dom(4)

How to dump contents of DOM object?

// Dumps the internal DOM tree back into string 
$str = $html->save();

// Dumps the internal DOM tree back into a file 
$html->save(‘result.htm‘);

How to customize the parsing behavior?

// Write a function with parameter "$element"
function my_callback($element) {
        // Hide all <b> tags 
        if ($element->tag==‘b‘)
                $element->outertext = ‘‘;


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

// Callback function will be invoked while dumping
echo $html;

simple_html_dom(4)