Here is the code for replace the ‘src’ attribute of the img tag from given html and return well formed html with new src content.

$doc = new DOMDocument();
@$doc->loadHTML($html);

$tags = $doc->getElementsByTagName(‘img’);

foreach ($tags as $tag) {
$old_src = $tag->getAttribute(‘src’);
$new_src_url = WEBURL.$old_src;
$tag->setAttribute(‘src’, $new_src_url);
}
$new_content = $doc->saveHTML();

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...