Have a look at this...
$strTexte = '<a href="http://localhost/Ad/img_1.jpg" target="_top" >
<img src="Ad/img_1.jpg" width="468" height="80" border="0">
</a>
~
<a href="http://localhost/Ad/img_2.jpg" target="_top" >
<img src="Ad/img_2.jpg" width="468" height="80" border="0">
</a>
~
<a href="http://localhost/Ad/img_3.jpg" target="_top" >
<img src="Ad/img_3.jpg" width="468" height="80" border="0">
</a>';
$arrCaptures = array();
$strMotif = '#<a href="(.*?)".*?<img src="(.*?)".*?</a>#s';
if(preg_match_all($strMotif, $strTexte, $arrCaptures)) {
print_r($arrCaptures);
} else {
echo 'Error : no match found !<br />' . "\n";
}
You will see that each HREF is contained in $arrCaptures[1], and each SRC is contained in $arrCaptures[2]. This will only work if there is <a href="{1}"<img src="{2}"</a>
where {1} is the link URL, {2} the image URL, and * is a wildcard. Simply, you need to open a link, put an image, and close the link for the script to work.
Please note that the variable $strTexte contains the contents of ad.txt. You could simply use file_get_contents('Ad.txt').
I hope I helped you 🙂