繁体   English   中英

如果链接内容为utf-8字符,则错误“ file_get_contents”

[英]Error “file_get_contents” if link content utf-8 character

我懂了

警告: file_get_contents(http://images.hotdeals.vn/images/03-01-2014/Bộ 2 Loa Xí Ngầu/51693_0_body_01.jpg) :无法打开流:HTTP请求失败!
在第60行的C:\\ xampp \\ htdocs \\ tasklist \\ controller \\ admin \\ addProduct.php中找不到HTTP / 1.1 404

当我尝试使用http://images.hotdeals.vn/images/03-01-2014/Bộ 2 Loa Xí Ngầu/51693_0_body_01.jpg下载图像时。
任何帮助。 谢谢。

问题是该目录名称。 这对我有用...

file_get_contents('http://images.hotdeals.vn/images/03-01-2014/'
        . rawurlencode('Bộ 2 Loa Xí Ngầu') . '/51693_0_body_01.jpg')

如果您需要更多动态的东西,请尝试此...

$url = 'http://images.hotdeals.vn/images/03-01-2014/Bộ 2 Loa Xí Ngầu/51693_0_body_01.jpg';

$info = parse_url($url);
$safePath = implode('/', array_map('rawurlencode', explode('/', $info['path'])));

$newUrl = sprintf('%s://%s%s', $info['scheme'], $info['host'], $safePath);

// http://images.hotdeals.vn/images/03-01-2014/B%E1%BB%99%202%20Loa%20X%C3%AD%20Ng%E1%BA%A7u/51693_0_body_01.jpg

此处演示-http: //ideone.com/Abr1OO

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM