如何连接code URL使用PHP样的浏览器做 [英] How to encode URL using php like browsers do

查看:249
本文介绍了如何连接code URL使用PHP样的浏览器做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的网址

http://www.example.com/Data/image/office-dôn-sì-à.jpg

我想在PHP中使用复制函数文件复制到我的服务器。所以,第一件事就是带code它这个(我认为浏览器做同样的事情)

I want to copy that file to my server using copy function in php. So the first thing is to encode it to this (I think browsers do the same thing)

http://www.example.com/Data/image/office-d%C3%B4n-s%C3%AC-%C3%A0.jpg

但是,如果使用功能的 urlen code 后,完整的URL将是连接coded到

But if I use function urlencode, full url will be encoded to

http%3A%2F%2Fwww.example.com%2FData%2Fimage%2Foffice-d%C3%B4n-s%C3%AC-%C3%A0.jpg

这是不是一个URL,并再没有我想要的东西。

which is not an URL anymore and not what I want.

任何帮助吗?

推荐答案

所以,在这里其他的答案在很大程度上忽略了你的帖子,它似乎。但愿我没有做过一样的。

So, the other answers here have largely ignored your post, it seems. Let's hope I have not done the same.

在我看来,你只是想带code基名?如果是真的,这个特设的功能应该做的伎俩:

It seems to me that you only want to encode the basename? If that is true, this ad-hoc function should do the trick:

function encode_basename($url) {
    $url = explode('/', $url);
    $base = array_pop($url);

    return implode('/', $url) . '/' . urlencode($base);
}
//returns: http://www.example.com/Data/image/office-d%25C3%25B4n-s%25C3%25AC-%25C3%25A0.jpg

这篇关于如何连接code URL使用PHP样的浏览器做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆