title: Get images from article in Joomla with php
body: <p>I'm trying edit a plugin which I use to add meta open graph tags to the header. The problem with it is that it would only let me choose one picture for the whole site.. this is what I've done:</p>
  
  <pre><code>preg_match_all('/&lt;img .*?(?=src)src=\"([^\"]+)\"/si', $hdog_base, $image);
  
  if (strlen($hdog_base) &lt;= 25) 
  {
      if (substr($image[0], 0, 4) != 'http') 
      {
          $image[0] = JURI::base().$image[0]; 
      }
      $hdog_image_tmp = $image[0];
  }
  else
  {
      if (substr($image[1], 0, 4) != 'http') 
      {
          $image[1] = JURI::base().$image[1]; 
      }
      $hdog_image_tmp = $image[1];
  }
  $hdog_image =   '&lt;meta property="og:image" content="'.$hdog_image_tmp.'" /&gt;
  ';
  </code></pre>
  
  <p>$hdog_base is the current webpage I'm on. 
  The first if-statement would show the very first picture, which is the logo (used for ex. homepage), and the else would show the second picture (which would be different on each page), but the result only comes out like this, no matter if I'm on the homepage or anywhere else on the site:</p>
  
  <pre><code>&lt;meta property="og:image" content="http://mysite.com/Array" /&gt;
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p>Thanks in advance,</p>
  
  <p>Update:
  The biggest fault I'm making is that I am trying to find the images in a url, not the actual webpage. But just the link. So how would I go on to get the contents of the current page in a string? Instead of $hdog_base, which is nothing but a link.</p>
  
  <p><strong>UPDATE, SOLVED:</strong></p>
  
  <p>I used</p>
  
  <pre><code>$buffer = JResponse::getBody();
  </code></pre>
  
  <p>to get the webpage in HTML</p>
  
  <p>and then DOM for the rest</p>
  
  <pre><code>$doc = new DOMDocument();
  @$doc-&gt;loadHTML($buffer);
  
  $images = $doc-&gt;getElementsByTagName('img');
  if (strlen($hdog_base) &lt;= 26) 
  {
      $image = $images-&gt;item(0)-&gt;getAttribute('src');
  } 
  else 
  {
      $image = $images-&gt;item(1)-&gt;getAttribute('src');
  }
  if (substr($image, 0, 4) != 'http') $image = JURI::base().$image;
  $hdog_image =   '&lt;meta property="og:image" content="'.$image.'" /&gt;
  ';
  </code></pre>
  
  <p>Thanks a lot <strong>cpilko</strong> for your help! :)</p>