0

I have the following image src in my page

<img src="http://path_to_image/platinum/getmedia?ID=97629047310&LOOT=50041223935" width="290" height="193">

and this code in my php

    $dom = new DOMDocument();
    $dom->loadHTML($page);

    foreach ($dom->getElementsByTagName('img') as $img) {
        $src = $img->attributes->getNamedItem('src')->nodeValue;
        if ($src{0} === '/') {
            $src = 'http://' . $server . $src;
        }
        $img->attributes->getNamedItem('src')->nodeValue = $src;
    }

    $page = $dom->saveHTML();

If I view $page after saveHTML the img src is

<img src="http://path_to_image/platinum/getmedia?ID=97629047310" width="290" height="193">
  • That's because of the ampersand (&) in the URL, look at the answer to this question, http://stackoverflow.com/questions/6379283/remove-amp-from-string-when-writing-to-xml-in-php, and close yours as it's a duplicate. – Rolando Isidoro Jun 27 '13 at 14:14
  • @Rolando Isidoro you were faster - I found event the same question on SO :) – furas Jun 27 '13 at 14:15
  • Thanks very much, I searched everything I could think of and never found that post. – user2528178 Jun 27 '13 at 14:55

0 Answers0