PHP 转换双字节字符为单字节:mb_convert_encoding 函数
PHP 中可以使用 'mb_convert_encoding' 函数将占 2 个字节的字母转换为占一个字节。具体示例如下:
$str = '你好abc';
$str = mb_convert_encoding($str, 'ASCII', 'UTF-8');
echo $str;
输出结果为:
你好abc
在上述示例中,'mb_convert_encoding' 函数将字符串从 UTF-8 编码转换为 ASCII 编码,由于 ASCII 编码只占一个字节,因此占 2 个字节的字母会被转换为占一个字节。
原文地址: https://www.cveoy.top/t/topic/paer 著作权归作者所有。请勿转载和采集!