I have a html snippet with an image somewhere inside it. I want to replace the value of the src attribute. I.e. get from something like:
<div style="position: relative" class="img-p"><a href="http://politiken.dk/indland/ECE2145750/nu-kommer-loven-om-alkolaase-spritbilister-skal-betale-6000-kr/"><img src="http://multimedia.pol.dk/archive/00802/RB_PLUS_Danskerne___802815p.jpg" width="369" height="253" alt="SPRITKONTROL" /></a></div>
To something like this:
<div style="position: relative" class="img-p"><a href="http://politiken.dk/indland/ECE2145750/nu-kommer-loven-om-alkolaase-spritbilister-skal-betale-6000-kr/"><img src="http://multimedia.pol.dk/archive/00802/SNOOTS.jpg" width="369" height="253" alt="SPRITKONTROL" /></a></div>
I've tried:
$content = preg_replace('/<img\s+src="([^"]+)"[^>]+>/i', '<img src="http://multimedia.pol.dk/archive/00802/SNOOTS.jpg"', $string);
echo htmlspecialchars($content);
But that removed the width and height and alt attributes.