dpmfur2635 2015-01-12 04:39
浏览 34
已采纳

函数chr(​​asciicode)在php中返回未知字母

I am using function chr and trying to echo between chr(161) and chr(206) (www.ascii.ca/cp874.htm)

It displays unknown alphabet

enter image description here

<?php

echo "ภาษาไทย" ;

for ($i=161 ;$i<206;$i++)
{
   echo "</BR>".chr($i)."</BR>";
}

?>

What should I do?

PS. File saved in utf-8

  • 写回答

2条回答 默认 最新

  • doushun4666 2015-01-12 04:53
    关注

    chr does not output "characters" or "alphabets"; in that sense it has a very misleading name.
    chr merely turns a decimal number into a raw byte. chr(161) just returns the byte xA1. You're then outputting this byte to the browser. The browser now interprets this byte using an encoding; whatever encoding you specified in your HTTP Content-Type header or in an HTML charset <meta> attribute.

    In your case it seems the browser is using UTF-8 to interpret the data. xA1 by itself doesn't make any sense in UTF-8, hence you get the "broken character" character instead. Try View → Encoding → Latin-1 instead in your browser to see other random characters appear.

    See What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text for more information on the topic of encodings.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?