title: Retrieve elements with xpath and DOMDocument
body: <p>I have a list of ads in the html code below.
  What I need is a PHP loop to get the folowing elements for each ad:</p>
  
  <ol>
  <li>ad URL (href attribute of <code>&lt;a&gt;</code> tag)</li>
  <li>ad image URL (src attribute of <code>&lt;img&gt;</code> tag)</li>
  <li>ad title (html content of <code>&lt;div class="title"&gt;</code> tag)</li>
  </ol>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="ads"&gt;
      &lt;a href="http://path/to/ad/1"&gt;
          &lt;div class="ad"&gt;
              &lt;div class="image"&gt;
                  &lt;div class="wrapper"&gt;
                      &lt;img src="http://path/to/ad/1/image.jpg"&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="detail"&gt;
                  &lt;div class="title"&gt;Ad #1&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/a&gt;
      &lt;a href="http://path/to/ad/2"&gt;
          &lt;div class="ad"&gt;
              &lt;div class="image"&gt;
                  &lt;div class="wrapper"&gt;
                      &lt;img src="http://path/to/ad/2/image.jpg"&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="detail"&gt;
                  &lt;div class="title"&gt;Ad #2&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I managed to get the ad URL with the PHP code below.</p>
  
  <pre class="lang-php prettyprint-override"><code>$d = new DOMDocument();
  $d-&gt;loadHTML($ads); // the variable $ads contains the HTML code above
  $xpath = new DOMXPath($d);
  $ls_ads = $xpath-&gt;query('//a');
  
  foreach ($ls_ads as $ad) {
      $ad_url = $ad-&gt;getAttribute('href');
      print("AD URL : $ad_url");
  }
  </code></pre>
  
  <p>But I didn't manage to get the 2 other elements (image url and title). Any idea?</p>