advanced_html_dom
advanced_html_dom copied to clipboard
find() returns object not array
This code
$html = str_get_html('<html><table><tr><td><td></body></html>');
var_dump(count(array_slice($html->find('tr'),0,1)));
with advanced_html_dom.php 0.0.11 fails:
Warning: array_slice() expects parameter 1 to be array, object given
whereas with 2016-12-11 simple_html_dom.php (1.5 ($Rev: 196 $)) it succeeds, outputting:
int(1)
Arrays are less useful. For example you can do $html->find('tr')->texts
and it will return an array of the texts.
I can see adding a to_array() method though.
Arrays are less useful.
Point taken, but the issue here is that teh drop-in replacement breaks existing code.
For example you can do $html->find('tr')->texts and it will return an array of the texts.
Thanks. OOI, why object to array not object to object?
The idea is that if the method is plural on a NodeList It will map that to each node in the list.
So you can do:
$html->find('a')->hrefs
and it will return all the hrefs on the page. Convenient, right?
I agree that's good.
My thought was just that it seems odd that find() delivers an object (unlike simple__html_dom) and text() accepts an object, but text() delivers an array.
That's a strange way to put it, I think you're misunderstanding something but I'm not sure what.
On Sun, Dec 11, 2016 at 8:29 PM, chrisjj [email protected] wrote:
I agree that's good.
My thought was just that it seems odd that find() delivers an object (unlike simple__html_dom) and text() accepts an object, but text() delivers an array.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/monkeysuffrage/advanced_html_dom/issues/11#issuecomment-266279329, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1afCC-GRMTfEP-AQpfkbB0YfXWf_XWks5rG-ylgaJpZM4LJ00Q .
Duplicate of #9