I have a list of ads in the html code below. I need a PHP loop to get the following elements for each declaration:
- Ad URL (href attribute of <a> tag)
- Image URL (src attribute of the
<img> ) - ad title (html content of the
<div class="title"> )
<div class="ads"> <a href="http://path/to/ad/1"> <div class="ad"> <div class="image"> <div class="wrapper"> <img src="http://path/to/ad/1/image.jpg"> </div> </div> <div class="detail"> <div class="title">Ad #1</div> </div> </div> </a> <a href="http://path/to/ad/2"> <div class="ad"> <div class="image"> <div class="wrapper"> <img src="http://path/to/ad/2/image.jpg"> </div> </div> <div class="detail"> <div class="title">Ad #2</div> </div> </div> </a> </div>
I managed to get the URL of the ad with the PHP code below.
$d = new DOMDocument(); $d->loadHTML($ads);
But I was not able to get the other two elements (image URL and name). Any idea?
source share