PHP内部编码 [英] PHP internal encoding

查看:110
本文介绍了PHP内部编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据bin2hex,我的PHP在内部使用UTF-8:

  echo bin2hex(ö); - > c3b6(utf-8)
echo bin2hex(utf8_decode(ö)); - > f6(ISO-8859)

但是mb_internal_encoding()和iconv_get_encoding()都说是ISO-8859 -1。

  echo mb_internal_encoding(); - > ISO-8859-1 
var_dump(iconv_get_encoding()); - > [ input_encoding] => string(10)ISO-8859-1[output_encoding] => string(10)ISO-8859-1[internal_encoding] => string(10)ISO-8859-1

UTF-8似乎是一个使用,但为什么会显示ISO-8859-1?

解决方案

这根本不奇怪。你的第一个检查是什么之间的报价。我假设您使用UTF-8保存该文件,这意味着您的字符串中有两个字节。这并不意味着内部编码是UTF-8,只是你有这两个字节你的字符串。


According to bin2hex my PHP is internally using UTF-8:

echo bin2hex("ö"); -> c3b6 (utf-8)
echo bin2hex(utf8_decode("ö")); -> f6 (ISO-8859)

But both mb_internal_encoding() and iconv_get_encoding() say it is ISO-8859-1.

echo mb_internal_encoding(); -> ISO-8859-1
var_dump(iconv_get_encoding()); ->  ["input_encoding"]=>  string(10) "ISO-8859-1"  ["output_encoding"]=>  string(10) "ISO-8859-1"  ["internal_encoding"]=>  string(10) "ISO-8859-1"

UTF-8 seems to apparently be the one it's using, but why is it showing ISO-8859-1 anyway?

解决方案

This is not strange at all. Your first check is for what is between the quotes. I assume you have saved the file using UTF-8 which means you have two bytes in your string. This does not imply that the internal encoding is UTF-8, just that you have those two bytes in you string.

这篇关于PHP内部编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆