Quick snippets to get you up to speed with the Yii PHP framework. By Neil McGuigan.
Pages
▼
Thursday, February 10, 2011
Simple HTML Dom is nice
Recently, I had to read a web page, make some minor changes to it, and save the results. I started with DOMDocument, but couldn't figure out how to write to a DOMNode.
Then I found Simple HTML DOM, and it's a nice piece of software.
you should use it for parsing html, for example, if you need to request a web page from yii, or if someone posts html to you.
you can put the simple_html_dom.php file in your components folder. you have to edit it slightly so that the class simple_html_dom {} is the first class on that page (just move it near the top)
I put simple_html_dom.php in extension folder, in a file in commands folder, include_one('/../extension/simple_html_dom.php'). Now I can using HTML DOM on the file in commands folder. thanks for share!
Neil, i've done this, but i got this error: Fatal error: Call to undefined function file_get_html() in C:\xampp\htdocs\hot\protected\controllers\HotController.php on line 127
Hi Mr Neil McGuigan, I've integrated Simple html dom in my Yii project. But I got the error: Trying to get property of non-object when i try: $img = $e->find('img')->outertext; var_dump($img); So I always use foreach loop to solve that problem :(. Could you help me, thank you so much!
How to config using DOMDocument on Yii? I don`t know using that! please help me!
ReplyDeleteyou should use it for parsing html, for example, if you need to request a web page from yii, or if someone posts html to you.
ReplyDeleteyou can put the simple_html_dom.php file in your components folder. you have to edit it slightly so that the class simple_html_dom {} is the first class on that page (just move it near the top)
Thanks Neil McGuigan!
ReplyDeleteI put simple_html_dom.php in extension folder, in a file in commands folder, include_one('/../extension/simple_html_dom.php'). Now I can using HTML DOM on the file in commands folder. thanks for share!
Neil,
ReplyDeletei've done this, but i got this error:
Fatal error: Call to undefined function file_get_html() in C:\xampp\htdocs\hot\protected\controllers\HotController.php on line 127
Hi Mr Neil McGuigan,
ReplyDeleteI've integrated Simple html dom in my Yii project.
But I got the error: Trying to get property of non-object when i try:
$img = $e->find('img')->outertext;
var_dump($img);
So I always use foreach loop to solve that problem :(.
Could you help me, thank you so much!