fork(3) download
  1. <?php
  2. $text = '<p>Hi, this is a test, here is an image<img src="http://m...content-available-to-author-only...e.com/beer.jpg" width="60" height="95" /> Because I like Beer!</p>';
  3. $domDocument = new DOMDocument;
  4. $domDocument->loadHTML($text, LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD);
  5. $imageNodeList = $domDocument->getElementsByTagName('img');
  6.  
  7. foreach ($imageNodeList as $Image) {
  8. $Image->setAttribute('src', 'lalala');
  9. $domDocument->saveHTML($Image);
  10. }
  11.  
  12. $text = $domDocument->saveHTML();
  13. echo $text;
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
<p>Hi, this is a test, here is an image<img src="lalala" width="60" height="95"> Because I like Beer!</p>