<?php $html = ' <div class="itemer"> <span class="pointer" onclick="z49()"> <center> </br> <img src="https://website.sitelop.com/small/amazon.cn/icon.jpg" alt="Amazon.com. Spend less. Smile more." style="width:36px;height:36px; border-radius: 20%;" > amazon.cn</center> </span> </div> <div class="itemer"> <span class="pointer" onclick="z50()"> <center> </br> <img src="https://website.sitelop.com/small/cnn.com/icon.jpg" alt="Breaking News, Latest News and Videos | CNN" style="width:36px;height:36px; border-radius: 20%;" > cnn.com</center> </span> </div>'; $dom = new DOMDocument(); $dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); $images = $dom->getElementsByTagName('img'); foreach ($images as $image) { $src = $image->getAttribute('src'); $type = pathinfo($src, PATHINFO_EXTENSION); $data = file_get_contents($src); $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data); $image->setAttribute("src", $base64); } $html = $dom->saveHTML(); echo $html; ?>