我如何找出一个字符有多少字节? [英] How do I find out how many bytes a character has?

查看:138
本文介绍了我如何找出一个字符有多少字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何知道一个角色有多少字节?

I was wondering how do I find out how many bytes does a character have?

推荐答案

如果你想知道那么PHP字符串中的字母有多少个UTF-8字节:

If you want to find out how many UTF-8 bytes a letter in a PHP string has then:

print strlen(mb_substr($string, 0, 1, "utf-8"));

strlen()返回原始字节长度,而 mb_substr()根据charset / encoding返回一个字符。在此示例中,从位置 0

strlen() returns the raw byte length, while mb_substr() returns a "character" according to the charset/encoding. In this example from position 0.

这篇关于我如何找出一个字符有多少字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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