【问题标题】:Problem with file_get_contents() and special charactersfile_get_contents() 和特殊字符的问题
【发布时间】:2011-06-14 17:49:32
【问题描述】:

我正在使用包含特殊字符的 url 的 file_get_contents()。我从维基百科中挑选了一些网址进行检查。

我的“test1.php”

    <?php
     header('Content-Type: text/html; charset=UTF-8');
      echo file_get_contents($_GET['url']);
    ?>

我测试的网址:(注意:这些链接中的特殊字符没有正确显示..点击链接查看地址栏的特殊字符)

http://localhost/te/test1.php?url=http://en.wikipedia.org/wiki/T%C3%A2i-l%C3%B4

---- 上面的 URL 工作并显示内容,但下面不起作用 ------

http://localhost/te/test1.php?url=http://en.wikipedia.org/wiki/Pha%CC%8Dk-oa-chhi_romanization

localhost/te/test1.php?url=http://en.wikipedia.org/wiki/Bb%C3%A1nl%C3%A1m_H%C5%8Dngggi%C3%A1n_P%C4%ABny%C4%ABn_H %C5%8Dng%C3%A0n

我尝试了 mb_convert_encoding() 但它没有解决...帮我解决这个问题。谢谢。

【问题讨论】:

  • 请注意,如果您所做的只是解码特殊字符而无需进一步验证,您可能会为用户在服务器上指定任意文件打开大门,这是一个巨大的安全风险。
  • 仅用于测试目的:我相信如果您为此网址创建一个带有文本框的表单,它将正常工作。当然,您需要像上面的示例一样在此文本框中粘贴百分比编码的 url。

标签: php special-characters file-get-contents


【解决方案1】:

为此,我相信您必须使用 . urlencode($变量);

【讨论】:

  • 为了使用 urlencode() 进行测试,我必须修改我的代码,否则它会编码所有 (: , / , ?)。我修改后的代码是 en.wikipedia.org/wiki/'.$str); ?> 我测试过的网址是:localhost/te/… 但仍然无法正常工作。无论如何感谢杰夫。有什么想法???
猜你喜欢
  • 1970-01-01
  • 2015-10-21
  • 2012-05-10
  • 2011-04-19
  • 1970-01-01
相关资源
最近更新 更多