douchenzhan3050 2014-05-21 00:48
浏览 92
已采纳

PHP:如何获取以ANSI编码的输入[重复]

This question already has an answer here:

When adding a get parameter such as ?key=é , PHP transforms that value immediately into UTF8. My script is not UTF8 and I must get the data in ISO-8859-1 by doing $_GET['key']

strlen of that value should be 1. Not 2.

How can I get that data in non-UTF8 without using a dependency such as mb or iconv.

</div>
  • 写回答

1条回答 默认 最新

  • donglu7286 2014-05-21 01:03
    关注

    When adding a get parameter such as ?key=é , PHP transforms that value immediately into UTF8. My script is not UTF8 and I must get the data in ISO-8859-1 by doing $_GET['key']

    This statement is incorrect. PHP is not responsible here — the web browser is sending data to the web server in the UTF-8 string encoding, and PHP is passing it on to your application in that same form.

    Keep in mind that "ANSI" is not a string encoding. It's a term sometimes used by Windows systems to (incorrectly!) refer to the system's native string encoding, which is usually Windows-1252 (similar to ISO-8859-1) on English systems, but can vary depending on the locale.

    strlen of that value should be 1. Not 2.

    To have strlen() return the length in characters, rather than in bytes, you would need to activate PHP's multibyte function overloading, which is a feature of the mbstring extension, or convert the string to a single-byte string encoding using iconv (which will be a lossy process).

    There is no way to perform this conversion without either mbstring, iconv, or something substantially similar.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了