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条)

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?