print file_get_content 给出 url、php 中的特殊字符
print file_get_content gives special characters in url, php
我想打印一张图片 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);
如果你想显示图像试试这个:
<?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
将包含原始图像数据!
您正在从 API 服务请求 PNG 图片,您应该使用适当的 headers 来显示图片,
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);
我想打印一张图片 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);
如果你想显示图像试试这个:
<?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
将包含原始图像数据!
您正在从 API 服务请求 PNG 图片,您应该使用适当的 headers 来显示图片,
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);