首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用$url-8字符的%编码复制($filename,UTF)?

如何使用$url-8字符的%编码复制($filename,UTF)?
EN

Stack Overflow用户
提问于 2011-03-25 08:10:34
回答 1查看 1.5K关注 0票数 1

这是怎么工作的?

代码语言:javascript
复制
copy("http://translate.google.com/translate_tts?tl=en&q=Love+Me", "/directory/loveme.mp3");

但这不是吗?

代码语言:javascript
复制
copy("http://translate.google.com/translate_tts?tl=hi&q=%26%232310%3B%26%232354%3B%26%232370%3B+%26%232327%3B%26%232379%3B%26%232349%3B%26%232368%3B",  "/directory/loveme.mp3");

如果我将两个URL都粘贴到浏览器中,它们都可以正常运行。但是第二个网址只复制了一个空白的mp3文件,而第一个网址复制了正确的MP3文件。

EN

回答 1

Stack Overflow用户

发布于 2011-03-25 08:24:39

在调用copy之前,尝试在URL上执行此操作。

代码语言:javascript
复制
function utf8RawUrlDecode ($source) {
    $decodedStr = "";
    $pos = 0;
    $len = strlen ($source);
    while ($pos < $len) {
        $charAt = substr ($source, $pos, 1);
        if ($charAt == '%') {
            $pos++;
            $charAt = substr ($source, $pos, 1);
            if ($charAt == 'u') {
                // we got a unicode character
                $pos++;
                $unicodeHexVal = substr ($source, $pos, 4);
                $unicode = hexdec ($unicodeHexVal);
                $entity = "&#". $unicode . ';';
                $decodedStr .= utf8_encode ($entity);
                $pos += 4;
            }
            else {
                // we have an escaped ascii character
                $hexVal = substr ($source, $pos, 2);
                $decodedStr .= chr (hexdec ($hexVal));
                $pos += 2;
            }
        } else {
            $decodedStr .= $charAt;
            $pos++;
        }
    }
    return $decodedStr;
}

这是我从docs for rawurldecode上的评论中得到的--向下滚动。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5427144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档