问题描述:

I have following string

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABVYAAAMACAIAAABAXKuVAAAAA3NCSVQICAjb4U/gAAAgAElEQVR4Xu....">

Now i want to replace "uploads/imag1.jpeg" to

"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABVYAAAMACAIAAABAXKuVAAAAA3NCSVQICAjb4U/gAAAgAElEQVR4Xu...."

i try this

$doc = new DOMDocument();

$doc->loadHTML('"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABVYAAAMACAIAAABAXKuVAAAAA3NCSVQICAjb4U/gAAAgAElEQVR4Xu...."');

$tags = $doc->getElementsByTagName('img');

foreach ($tags as $t)

{

$t->setAttribute('src','uploads/imag1.jpeg');

echo $doc->saveHTML();

}

But this is not working properly.

i have path following correct path

localhost:83/mysite/images/imag1.jpg

But My code gives me following wrong path,

localhost:83/mysite/image/uploads/imag1.jpg

Because of this issue replacement not works proper.

How can i do this replacement.

网友答案:

Here is solution with PHP:

<?php 

   echo '<img src="data:image/png;base64,'. base64_encode(file_get_contents("uploads/imag1.jpeg")) .'"/>;

?>
相关阅读:
Top