How is correct wayt to interate all elements return by xpath->evaluate
?
i have that structure:
<?
$html = '
<div class="xGh" style="background-image: url(\'name_file0.jpg\');"></div>
<div class="xGh" style="background-image: url(\'name_file1.jpg\');"></div>
<div class="xGh" style="background-image: url(\'name_file2.jpg\');"></div>
<div class="xGh" style="background-image: url(\'name_file3.jpg\');"></div>
';
libxml_use_internal_errors(true);
$dom = new domDocument('1.0', 'utf-8');
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$xpath = new DOMXPath($dom);
$img = $xpath->evaluate('substring-before(substring-after(//div[@class=\'xGh\']/@style, "background-image: url(\'"), "\')")');
echo $img;//name_file0.jpg
edit
With that loop in can iterate my object, but not correct result:
<?
$html = '
<div class="xGh" style="background-image: url(\'name_file0.jpg\');"></div>
<div class="xGh" style="background-image: url(\'name_file1.jpg\');"></div>
<div class="xGh" style="background-image: url(\'name_file2.jpg\');"></div>
<div class="xGh" style="background-image: url(\'name_file3.jpg\');"></div>
';
libxml_use_internal_errors(true);
$dom = new domDocument('1.0', 'utf-8');
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$xpath = new DOMXPath($dom);
$items = $xpath->query('//div[@class="xGh"]');
for($i = 0; $i < $items->length; $i++)
{ $ci = $xpath->evaluate("substring-before(substring-after(//*[@class=\"xGh\"]/@style, \"background-image: url('\"), \"')\")");
echo $ci;
}//name_file0.jpgname_file0.jpgname_file0.jpgname_file0.jpg
The output needed is :
name_file0.jpgname_file1.jpgname_file2.jpgname_file3.jpg
Where is the correct place to put one count iterator in that loop, to give sequence files not the same?
How iterate to return others?