Jump to content

How to dump contents of DOM objec


Recommended Posts



I write this script with simple_html_do parser lib.


now how can I save results


I use $html->save('result.htm');


but display main web page url not my result

<?phpinclude_once('simple_html_dom.php');// Create DOM from URL$html= file_get_html("http://www.digionline.ir/Allprovince/viewcat/%D9%82%DB%8C%D9%85%D8%AA-%D8%AE%D8%B1%DB%8C%D8%AF-%D9%81%D8%B1%D9%88%D8%B4-%D9%85%D8%B4%D8%AE%D8%B5%D8%A7%D8%AA-%D9%87%D8%A7%D8%B1%D8%AF-%D8%AF%D9%8A%D8%B3%D9%83-%D9%83%D8%A7%D9%85%D9%BE%D9%8A%D9%88%D8%AA%D8%B1/cat=20101",10);foreach($html->find('ul#product-page-product') as $ul) {{       foreach($ul->find('li') as $li)        {              $item['title']= $li->find('span.product-page-detail-wrapper-text', 0)->plaintext;                $item['price'] = $li->find('span.product-detail-wrapper-price', 0)->plaintext;                $lis[] = $item;       }}                            } $ul = array();echo$titles="<b>نام محصول:</b>". $item['title'] . "</br>  ";echo$prices="<b>قیمت:</b>". $item['price'] . "</br>  ";echo$titles="<b>نام محصول:</b>". $item['title'] . "</br>  ";echo$prices="<b>قیمت:</b>". $item['price'] . "</br>  ";$html->save('result.htm');?> 


Link to comment
Share on other sites

I want display in result.htm display this :


$titles="<b>نام محصول:</b>". $item['title'] . "</br> ";echo$prices="<b>قیمت:</b>". $item['price'] . "</br> ";echo$titles="<b>نام محصول:</b>". $item['title'] . "</br> ";echo$prices="<b>قیمت:</b>". $item['price'] . "</br> ";


: led

قیمت: 25000



but when use $html->save('result.htm') displaying main web pag of


$html= file_get_html("http://www.digionline.ir/Allprovince/viewcat/%D9%82%DB%8C%D9%85%D8%AA-%D8%AE%D8%B1%DB%8C%D8%AF-%D9%81%D8%B1%D9%88%D8%B4-%D9%85%D8%B4%D8%AE%D8%B5%D8%A7%D8%AA-%D9%87%D8%A7%D8%B1%D8%AF-%D8%AF%D9%8A%D8%B3%D9%83-%D9%83%D8%A7%D9%85%D9%BE%D9%8A%D9%88%D8%AA%D8%B1/cat=20101",10);




please run top script..

Link to comment
Share on other sites

Using $html->save saves the document in the $html variable. You're just echoing out HTML code. You need to make that code part of the document in the $html variable. Or, if that is the only thing you want to save, then build a string containing everything you want and use file_put_contents to save it to a file.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...