[英]base64 encoding for image src
When I echo the following: 当我回应以下内容时:
$im_dec = base64_decode($row['image']);
I obtain the desired URL: 我获得了所需的URL:
https://www.ft.com/__origami/service/image/v2/images/raw/http%3A%2F%2Fprod-upp-image-read.ft.com%2F1263ad72-2d9a-11e7-9555-23ef563ecf9a?source=next&fit=scale-down&compression=best&width=210
Then I use this URL to be the src of my img: 然后,我使用此URL作为img的src:
$newImage = $dom->createElement('img');
$newImage->setAttribute("src", $im_dec);
$newImage->setAttribute("class", "articleImage");
$newTitle->appendChild($newImage);
And when I check the src attribute in my html document, I get a modified url where &
is replaced by &
当我检查html文档中的src属性时,会得到一个修改的url,其中
&
替换为&
for example and many more weird stuff.. 例如,还有更多奇怪的东西。
Some characters were modified and I don't know how to avoid it. 有些字符已修改,我不知道如何避免。 I tried many things but I thought base64 encoding would work...
我尝试了很多事情,但我认为base64编码可以工作...
Help please! 请帮助!
You can convert an image to base64 encoding with the following example: 您可以使用以下示例将图像转换为base64编码:
$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.