簡體   English   中英

print file_get_content在url,php中給出特殊字符

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM