title: PHP replace image src and add a new attribute in image tag from a string containing different html tags
body: <p>I have a site where i get products description from database and decode html like this in PHP and display it on webpage frontend:</p>
  
  <pre><code>$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
  </code></pre>
  
  <p>It returns html like the following:</p>
  
  <pre><code>&lt;div class="container"&gt;
   &lt;div class="textleft"&gt;
    &lt;p&gt;
     &lt;span style="font-size:medium"&gt;
      &lt;strong&gt;Product Name:&lt;/strong&gt;
     &lt;/span&gt;
     &lt;br /&gt;
     &lt;span style="font-size:14px"&gt;Some description here &lt;a href="some-link"&gt;Click here to see full details.&lt;/a&gt;&lt;/span&gt;
     &lt;/p&gt;
   &lt;/div&gt;
   &lt;div class="imageblock"&gt;
    &lt;a href="some-link"&gt;
     &lt;img src="http://myproject.com/image/catalog/image1.jpg" style="width: 500px; height: 150px;" /&gt;
    &lt;/a&gt;
   &lt;/div&gt;
   &lt;div style="clear:both"&gt;
  &lt;/div&gt;
  &lt;div class="container"&gt;
   &lt;div class="textleft"&gt;
    &lt;p&gt;
     &lt;span style="font-size:medium"&gt;
      &lt;strong&gt;Product Name:&lt;/strong&gt;
     &lt;/span&gt;
     &lt;br /&gt;
     &lt;span style="font-size:14px"&gt;Some description here &lt;a href="some-link"&gt;Click here to see full details.&lt;/a&gt;&lt;/span&gt;
     &lt;/p&gt;
   &lt;/div&gt;
   &lt;div class="imageblock"&gt;
    &lt;a href="some-link"&gt;
     &lt;img src="http://myproject.com/image/catalog/image2.jpg" style="width: 500px; height: 150px;" /&gt;
    &lt;/a&gt;
   &lt;/div&gt;
   &lt;div style="clear:both"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>There could be many images in the product description. I have added just 2 in my example. What I need to do is replace src of every image with <code>src="image/catalog/blank.gif"</code> for all images and add a new attribute </p>
  
  <pre><code>data-src="http://myproject.com/image/catalog/image1.jpg" 
  </code></pre>
  
  <p>for image 1 and</p>
  
  <p><code>data-src="http://myproject.com/image/catalog/image2.jpg"</code></p>
  
  <p>for image 2. data-src attribute should get the original src value of each image. How can I achieve that?
  I have tried preg_replace like following</p>
  
  <pre><code>$data['description'] = preg_replace('((\n)?src="\b.*?")', 'src="image/catalog/blank.gif', $data['description']);
  </code></pre>
  
  <p>It replaces src attribute of every image, but how can i add data-src with original image path. I need this before page load, so is there any way to do it with PHP?</p>