title: PHP function to retrieve all images and their attributes from given html string and save to array and returns array
body: <p>I need to write php function to retrieve all images attributes like src,alt, height, width from given html string and store those attributes into array result. i need this function to return the array result for further processing like saving into database, thumbnail creation ...etc. </p>
  
  <p>i have wrote the following function but i am not satisfied as i am not able to extract elements other then scr</p>
  
  <pre><code> $url = '&lt;ul&gt; &lt;li&gt; &lt;img src="http://www.sayidaty.net/sites/default/files/imagecache/645xauto/01/04/2015/1427896207_sliderfashionshoot.jpg"/&gt; &lt;/li&gt; &lt;li&gt; &lt;img src="http://www.sayidaty.net/sites/default/files/imagecache/645xauto/01/04/2015/1427896207_1.jpg"/&gt; &lt;/li&gt; &lt;li&gt; &lt;img src="http://www.sayidaty.net/sites/default/files/imagecache/645xauto/01/04/2015/1427896207_2.jpg"/&gt; &lt;/li&gt; &lt;li&gt; &lt;img src="http://www.sayidaty.net/sites/default/files/imagecache/645xauto/01/04/2015/1427896207_5.jpg"/&gt; &lt;/li&gt; &lt;li&gt; &lt;img src="http://www.sayidaty.net/sites/default/files/imagecache/645xauto/01/04/2015/1427896207_4.jpg"/&gt; &lt;/li&gt; &lt;li&gt; &lt;img src="http://www.sayidaty.net/sites/default/files/imagecache/645xauto/01/04/2015/1427896207_3.jpg"/&gt; &lt;/li&gt; &lt;li&gt; &lt;img src="http://www.sayidaty.net/sites/default/files/imagecache/645xauto/01/04/2015/1427896207_6.jpg"/&gt; &lt;/li&gt; &lt;/ul&gt; ';
  
  function getItemImages($content)
  {
      $dom = new domDocument;
      $dom-&gt;loadHTML($content);
      $dom-&gt;preserveWhiteSpace = false;
  
      $elements = $dom-&gt;getElementsByTagName('img');
  
    if($elements-&gt;length &gt;= 1) {
      $url = array();
      $title = array();
      foreach($elements as $element) {
          $url[] = $element-&gt;getAttribute('src');
          $Title[] = $element-&gt;getAttribute('title');
      }
      return ($url);
  }
  </code></pre>