[英]print file_get_content gives special characters in url, php
我想打印一个图片网址,但它给了我特殊的字符。 我尝试了file_get_contents中的每个解决方案- URL中的特殊字符 - 特殊情况但它没有解决它。
我的代码:
$urlgeo = "http://geodata.nationaalgeoregister.nl/top25raster/wms?request=GetMap&service=WMS&version=1.3.0&request=GetMap&layers=top25raster&styles=&bbox=146000,451000,149000,454000&width=600&height=600&srs=EPSG:28992&format=image/png";
print file_get_contents($urlgeo);
您正在从API服务请求PNG图像,您应该使用适当的标题来显示图像,
header('Content-Type: image/png');
$urlgeo = "http://geodata.nationaalgeoregister.nl/top25raster/wms?request=GetMap&service=WMS&version=1.3.0&request=GetMap&layers=top25raster&styles=&bbox=146000,451000,149000,454000&width=600&height=600&srs=EPSG:28992&format=image/png";
print file_get_contents($urlgeo);
如果要显示图像,请尝试以下操作:
<?php
$urlgeo = "http://geodata.nationaalgeoregister.nl/top25raster/wms?request=GetMap&service=WMS&version=1.3.0&request=GetMap&layers=top25raster&styles=&bbox=146000,451000,149000,454000&width=600&height=600&srs=EPSG:28992&format=image/png";
echo "<img src='data:image/png;base64," . base64_encode(file_get_contents($urlgeo)) . "'>";
?>
它获取图像并在base64中编码。
稍后如果您需要原始图像数据,只需将base64_decode
:
$raw_image = base64_decode($encodedImg):
其中$encodedImg
是base64编码的字符串。 $raw_imag
将包含原始图像数据!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.