fork download
  1. <?php
  2.  
  3. $html = <<<HTML
  4. <div id="res">Some text inside DIV
  5. <img
  6. class="size-full wp-image-1561 "
  7. alt="Class-A warehouse facility developed by Panattoni Europe in Germany for Rudolph Logistik Gruppe."
  8. src="http://e...content-available-to-author-only...e.com/wp-content/uploads/2012/12/Gruppe.jpg">
  9. <img
  10. alt="Class-A warehouse facility developed by Panattoni Europe in Germany for Rudolph Logistik Gruppe."
  11. src="http://e...content-available-to-author-only...e.com/wp-content/uploads/2012/12/Gruppe.jpg">
  12. </div>
  13. HTML;
  14.  
  15. $dom = new DOMDocument();
  16. @$dom->loadHTML($html); // Using @ to hide any parse warning sometimes resulting from markup errors
  17. $dom->preserveWhiteSpace = false;
  18. $images = $dom->getElementsByTagName('img');
  19. $imgs = array();
  20. foreach($images as $img) {
  21. if ($img->attributes->getNamedItem("class") != null) {
  22. $imgs[] = $img;
  23. }
  24. }
  25. foreach($imgs as $img) {
  26. $img->parentNode->removeChild($img);
  27. }
  28.  
  29. $str = $dom->saveHTML();
  30. echo $str;
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://w...content-available-to-author-only...3.org/TR/REC-html40/loose.dtd">
<html><body><div id="res">Some text inside DIV
<img alt="Class-A warehouse facility developed by Panattoni Europe in Germany for Rudolph Logistik Gruppe." src="http://e...content-available-to-author-only...e.com/wp-content/uploads/2012/12/Gruppe.jpg"></div></body></html>