- str_replace: documentation ( source)
- preg_replace: documentation ( source)
<?php
$html = <<<EOF
<p>asdasd</p>
<img src="img1.jpg" style="width: 180px;">
<p>asdasd</p>
<img src="img2.jpg" style="width: 180px;">
<p>asdasd</p>
<img src="img3.jpg" style="width: 180px;">
<p>asdasd</p>
<img src="img4.jpg" style="width: 180px;">
EOF;
$dom=new DOMDocument();
$dom->loadHTML($html);
$imgs = $dom->getElementsByTagName("img");
foreach($imgs as $img){
$img->removeAttribute('style');
$img->setAttribute( 'src' , 'thumbnail.php?img=' . $img->getAttribute('src') );
}
echo preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), '', $dom->saveHTML()));