Skip to content

Wrong elements order #173

@AliN11

Description

@AliN11

Hi. Consider this string (note that the first img tag is between p tag):

$str = '<p><img src="http://example.com/first.jpg"></p><img src="http://example.com/second.jpg">';

With this PHP code:

$dom = (new Dom)->load($str);
$images = $dom->find('img');

foreach ($images as $image) {
    echo $image->src;
}

Expected output:

http://example.com/first.jpg
http://example.com/second.jpg

Actual output:

http://example.com/second.jpg
http://example.com/first.jpg

Furthermore, below code returns second element. while it should return first element:

$image = $dom->find('img', 0);
$image->src; // http://example.com/second.jpg

I mean, I get wrong elements order. Any help?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions