How to call 2 tags for one foreach with simple html dom?
<?php
require_once("simple_html_dom.php");
$str='<img src="./1.jpg" /><span>image1</span><img src="./2.jpg" /><span>image2</span>';//still have more 'img' and 'span'
$html = str_get_html($str);
foreach($html->find('img') as $content){
echo $content.'<br />';
//echo <span> inner html
}
?>
I want to get the result like:
<img src="./1.jpg" />
image1
<img src="./2.j开发者_运维问答pg" />
image2
one img
and behind span
for one unit. Thanks.
You could do this.
$img = $html->find("img");
$span = $html->find("span");
for($i=0;$i<count($img);$i++) {
echo $img[$i] . "<br />" . $span[$i];
}
精彩评论