title: How to display fetched image url data?
body: <p>I'm halfway through figuring out a little project of mine, where I basically fetch a page's images, and then redisplay them on another site of mine. While I'm doing this for purposes of displaying random images of my artwork (won't waste your time explaining the details), I'll use the following example because it basically will do exactly what I'm attempting to do.</p>
  
  <p>Right now what I'm able to do is fetch all image links from a given page, but I don't know how to re-display them as images on a website. Currently the data I get looks like this (test I did): <a href="http://www.wilsonschlamme.com/wiki.php" rel="nofollow noreferrer">http://www.wilsonschlamme.com/wiki.php</a></p>
  
  <p>Array</p>
  
  <pre><code>(
  [0] =&gt; https ://kfjhiakwhefkiujahefawef/awoefjoiwejfowe.jpg
  
  [1] =&gt; https ://oawiejfoiaewjfoajfeaweoif/awoeifjao;iwejfoawiefj.png
  
  )
  </code></pre>
  
  <p>*fyi as you can see, on the link the urls/file names are different each time. But it still successfully pulls the file names!</p>
  
  <p>*in case you're curious as to where I'm pulling the img information from, it's a nice little wiki random img generator: <a href="http://commons.wikimedia.org/wiki/Special:Random/File" rel="nofollow noreferrer">http://commons.wikimedia.org/wiki/Special:Random/File</a></p>
  
  <p>So that's pretty cool, happy to get this far because I'm very new to PHP. But what I now need to do, is RE display the FIRST image the array picks up, which is img 0. If you're wondering why I'm going through this headache, it has to do with random images, I'm going to be dealing with them, so naturally I need the site to pick up whatever image it finds, regardless of file name.</p>
  
  <p>So likewise, I'm thinking perhaps I replace the code in this current php I'm working with that is displaying this array in text format on the above test link, and instead have some code that takes [0] array, and displays that as an actual image instead, in other words pulls the image from that link, like a &lt; img src="https://_____</p>
  
  <p>How to do that exactly is where I'm lost. The desired output, is a website that shows the images from the array that is being gathered. So, this website would just be showing images, the fetched images. Literally images, not just the text.</p>
  
  <p>Any thoughts? Thanks so much for reading this. -Wilson</p>
  
  <p>The PHP code that's doing this:</p>
  
  <pre><code>&lt;?php
  /*
  Credits: Bit Repository
  URL: http://www.bitrepository.com/
  */
  
  $url = 'http://commons.wikimedia.org/wiki/Special:Random/File';
  
  // Fetch page
  $string = FetchPage($url);
  
  // Regex that extracts the images (full tag)
  $image_regex_src_url = '/&lt;img[^&gt;]*'.
  
  'src=[\"|\'](.*)[\"|\']/Ui';
  
  preg_match_all($image_regex, $string, $out, PREG_PATTERN_ORDER);
  
  $img_tag_array = $out[0];
  
  echo "&lt;pre&gt;"; print_r($img_tag_array); echo "&lt;/pre&gt;";
  
  // Regex for SRC Value
  $image_regex_src_url = '/&lt;img[^&gt;]*'.
  
  'src=[\"|\'](.*)[\"|\']/Ui';
  
  preg_match_all($image_regex_src_url, $string, $out, PREG_PATTERN_ORDER);
  
  $images_url_array = $out[1];
  
  echo "&lt;pre&gt;"; print_r($images_url_array); echo "&lt;/pre&gt;";
  
  // Fetch Page Function
  
  function FetchPage($path)
  {
  $file = fopen($path, "r"); 
  
  if (!$file)
  {
  exit("The was a connection error!");
  } 
  
  $data = '';
  
  while (!feof($file))
  {
  // Extract the data from the file / url
  
  $data .= fgets($file, 1024);
  }
  return $data;
  }
  
  
  
  
  for($i=0; $i&lt;count($arr1); $i++) {
  echo '&lt;img src="'.$arr1[$i].'"&gt;';
  }
  
  ?&gt;
  </code></pre>