我試圖在我的URL中實現一些URI編碼的文件名,但是遇到了uri_escape和uri_escape_utf8的一些奇怪問題,它們在表現上不一致。Perl uri_escape_utf8不一致的行爲(或程序員錯誤!)
使用perl的命令行:
[email protected]:$ perl
use URI::Escape;
print uri_escape_utf8("\"quotes\"_in_a_filename.pdf");
%22quotes%22_in_a_filename.pdf
完美,正是我想要的。然後在我的代碼:
print STDERR uri_escape_utf8("\"quotes\"_in_a_filename.pdf");
print STDERR uri_escape("\"quotes\"_in_a_filename.pdf");
這導致我的應用程序日誌文件中獲取以下行:
"quotes"_in_a_filename.pdf
"quotes"_in_a_filename.pdf
奇怪的是,代碼的應用程序相同的位工作得很好用空格的文件名,並(例如)正確輸出:
my%20pdf%20with%20spaces.pdf
我有點困惑,不知道下一步要找什麼解決方案。任何幫助感激地讚賞。
乾杯,
[R
當我運行你的第一個例子程序時,我得到了引號「_in_a_filename.pdf」。 – daxim 2010-08-19 17:02:18