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

时间:2016-03-18 09:54:47

标签: php character-encoding file-get-contents

我想打印一个图片网址,但它给了我特殊的字符。我尝试了file_get_contents - Special characters in URL - Special case中的每个解决方案,但它没有解决它。

我的代码:

$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);

2 个答案:

答案 0 :(得分:2)

您正在从API服务请求PNG图像,您应该使用适当的标题来显示图像,

        builder.Register(c => new ExternalEventsBus(CreateExternalEventBus()))
 .As<IExternalEventsBus>().SingleInstance();

public class ExternalEventsBus:IExternalEventsBus
{
    private IBus Bus;

    public ExternalEventsBus(IBus bus)
    {
        Bus = bus;
    }

    public async Task Send(object message, Guid documentProviderId)
    {
        await Bus.Advanced.Routing.Send(documentProviderId.ToString("n"), message);

    }

    public Task Send(object message, DocumentProvider documentProvider)
    {
        if (!string.IsNullOrWhiteSpace(documentProvider.RebusQueueConnectionString))
            return Send(message, documentProvider.Id);

        return Task.FromResult(true);
    }

    public void Dispose()
    {
        if(Bus!=null)
            Bus.Dispose();
    }
}

答案 1 :(得分:0)

如果您想要显示图片,请尝试以下操作:

<?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将包含原始图像数据!