by using PHP, I would like to get all the href and src in the image URL, where each img src will assign with each a href like this :
<a href="http://example.com/src/abc.png"><img src="http://example.com/res/bca.png"></a>
And this is the code that i already created.
$dom = new domDocument;
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$links = $dom->getElementsByTagName('a');
$images = $dom->getElementsByTagName('img');
$tags_links = array();
$tags_img = array();
foreach ($links as $link)
{
$tags_links [] = $link->getAttribute('href');
}
foreach ($images as $image)
{
$tags_img [] = $image->getAttribute('src');
echo "<a href =\"".$url .$link->getAttribute('href')."\"><img src=\"".$url.$image->getAttribute('src')."\">";
}
But what i get is the last html assign with each img src
<a href ="http:../port287.html"><img src=../port2.png">
Any suggestion on how can i assign it like
<a href ="http:../port2.html"><img src=../port2.png">
<a href ="http:../port3.html"><img src=../port3.png">