Monday, January 2, 2017

Find method not working properly - A possible bug in simple_html_dom library for PHP

simple_html_dom library for PHP features a strange behavior in version 1.5. I think this is a bug.


Scenario:

You use str_get_html to load a string to html dom object

You add dynamic object with class .a2 to an existing object .a1, by modifying its innertext property.

You call find() method to search for .a2 objects, like this:
$html->find('.a2')


It returns 0 results. Nothing can be found.



The problem is probably that updates using innertext are not getting converted to proper HTML DOM nodes.

The workaround is to save HTML DOM object to string, after setting innertext value, and then to load it back again from string to a new HTML DOM object.


Sample code:



$str2=(string)$html;
$html=str_get_html($str2);

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...