新手关于mb_strlen的有关问题
新手关于mb_strlen的问题。
不太明白这三次调用的返回值。。
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpecho mb_strlen("我的名字") . "<br/>"; //12echo mb_strlen("我的名字","UTF-8") . "<br>"; //4echo mb_strlen("我的名字","GBK") //6?>
代码保存在l.php里面,文件编码为utf8
关于mb_strlen 的第二个encoding参数。PHP手册上这么写的:
"The encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used."
我想知道那个internal character encoding是指哪个编码,在哪里配置的。
还有,对于这个函数的返回值 是这么写的
"Returns the number of characters in string str having character encoding encoding . A multi-byte character is counted as 1. "
多字节的字符按1来计算。
那为干什么第一次调用 会返回12,第二次调用居然返回6了。。 不太明白,希望帮解释 一下,谢谢了!
------解决方案--------------------
------解决方案--------------------
- PHP code
echo mb_strlen("我的名字") . "<br>"; //12echo mb_strlen("我的名字","UTF-8") . "<br>"; //4echo mb_strlen("我的名字","GBK") //6<br><font color="#e78608">------解决方案--------------------</font><br>首先你的文件编码一定是utf-8,而且你的mb_internal_encoding是类似于ISO-8859-1<br>然后要知道1个utf8汉字为3字节,gb是2字节,mb_strlen把多字节字算作1,所以会得出<br><?php <br />echo mb_strlen("我的名字") . "<br>"; //未给定编码,按默认 ISO-8859-1 计算,一个utf8汉字为3<br>echo mb_strlen("我的名字","UTF-8") . "<br>"; //给定正确编码,一个汉字为1<br>echo mb_strlen("我的名字","GBK") //给定错误编码,GBK 一个汉字算2,但你的文件是utf8,所以为4 * 3 = 12字节 / 2 = 6个gbk字<br>?><div class="clear"> </div>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

1g memory is 1024MB. g stands for "GB", which means "gigabyte" in Chinese, and MB refers to "megabyte"; GB and MB are both commonly used to indicate the storage capacity of computer hard drives, memories and other storage media with larger capacities. The conversion rate between GB and MB is approximately equal to 1000 (1024), that is, "1GB=1024MB".

1MB of storage capacity is equivalent to 2 to the 20th power bytes, or 1,048,576 bytes. MB is a storage unit in computers, pronounced as "mega"; because 1MB is equal to 1024KB, and 1KB is equal to 1024B (bytes), so 1MB is equal to 1048576 (1024 *1024) bytes.

1g is equal to 1024MB memory capacity. The full name of g is "GB", which means "gigabyte" in Chinese. It is a decimal unit of information measurement and is often used to indicate the storage capacity of computer hard drives, memories and other large-capacity storage media. The conversion rate between GB and MB is approximately equal to 1000 (1024), that is, "1GB = 1024MB".

Java uses the isLetterOrDigit() function of the Character class to determine whether a character is a letter or number. In Java programming, we often need to perform some operations and judgments on characters. One of the common needs is to determine whether a character is a letter or a number. Java provides the isLetterOrDigit() function of the Character class to help us implement this function. The Character class is a wrapper class used to operate and judge characters.

Use Java's Character.isDefined() function to determine whether a character is a defined character. In Java programming, sometimes you need to determine whether a character is a defined character. For convenience, Java provides the isDefined() function of the Character class, which can help us quickly determine whether a character is a defined character. This article explains how to use this function and provides some code examples. Character class represents a single character in Java

Interpretation of Java documentation: Detailed explanation of the isAlphabetic() method of the Character class 1. Overview In the Java Character class, the isAlphabetic() method is used to determine whether a given character is an alphabetic character. It returns a boolean value, true indicating that the given character is an alphabetic character, false indicating that the given character is not an alphabetic character. This article will provide a detailed analysis of the use and principle of this method, and provide code examples to help readers better understand

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Use Java's Character.isLetterOrDigit() function to determine whether a character is a letter or number. In Java, we often need to determine whether a character is a letter or number. In order to simplify this process, Java provides a built-in function Character.isLetterOrDigit(), which can help us quickly complete this judgment. The Character.isLetterOrDigit() function accepts a character as a parameter
