Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php rawurlencode()的奇怪行为……如何使其工作?_Php - Fatal编程技术网

Php rawurlencode()的奇怪行为……如何使其工作?

Php rawurlencode()的奇怪行为……如何使其工作?,php,Php,我在我的PHP项目中发现了一件很烦人的事情。 我的网页可以存储文件,然后允许用户下载/显示它们。因为这意味着我制作了URL链接,链接到处理文件名并提供文件名的模型类,所有这些都可以在这里使用 但是对于文件,它们的名称会出现问题,特别是空格和特殊字符,这在网站的语言中非常常见。我的系统通过单击链接来提供文件名。下载脚本会终止所有热链接尝试,因此只有可单击的链接才能完成此任务 所以我遇到了处理那些特殊文件名的问题。我知道rawurlencode函数,我想使用它,但是它的行为非常奇怪。这是我的代码:对

我在我的PHP项目中发现了一件很烦人的事情。 我的网页可以存储文件,然后允许用户下载/显示它们。因为这意味着我制作了URL链接,链接到处理文件名并提供文件名的模型类,所有这些都可以在这里使用

但是对于文件,它们的名称会出现问题,特别是空格和特殊字符,这在网站的语言中非常常见。我的系统通过单击链接来提供文件名。下载脚本会终止所有热链接尝试,因此只有可单击的链接才能完成此任务

所以我遇到了处理那些特殊文件名的问题。我知道rawurlencode函数,我想使用它,但是它的行为非常奇怪。这是我的代码:对于所有文件,我都在foreach循环中使用了它,因此$key出现了,但我将为一个索引显示它

echo $this->files[$key]; 
//shows name of file: a č o.png

echo rawurlencode($this->files[$key]); 
//shows translated name: a%20%C4%8D%20o.png

echo URL; 
//gives (yes, it is local XAMPP test server) : http://127.0.0.1/

echo '<a href="' . URL . 'file/show/' . $this->files[$key] . '" target="_blank"> Show file </a>';
// gives link leading to: 127.0.0.1/file/show/a č o.png
同样,不翻译空格和字符。是我的系统闹鬼了还是有人有线索

我还尝试了urlencode,它按照预期将空格转换为+,但是它也不能处理所有特殊字符。 还有其他功能吗


我正在使用UTF-8的所有东西

我不能在这里重现这个问题。您能在另一台机器上重现该问题吗?//给出了指向:[……]的链接-您在哪里以及如何检查该问题?特别是,输出127.0.0.1/文件%2Fshow%2Fačo.png不太可能是调用rawurlencode引起的
echo '<a href="' . URL . 'file/show/' . rawurlencode($this->files[$key]) . '" target="_blank"> Show file </a>';
//gives link leading to: 127.0.0.1/file%2Fshow%2Fa č o.png

$address = rawurlencode($this->files[$key]);
echo '<a href="' . URL . 'file/show/' . $address . '" target="_blank"> Show file </a>';
//gives link leading to: 127.0.0.1/file/show/a č o.png
echo '<a href="' . URL . 'file/show/';
echo rawurlencode($this->files[$key]);
echo '" target="_blank"> Show file </a>';
//gives link leading to: 127.0.0.1/file/show/a č o.png