Home Backend Development PHP Tutorial 新手关于mb_strlen的有关问题

新手关于mb_strlen的有关问题

Jun 13, 2016 am 10:45 AM
character encoding mb quot 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?>
Copy after login


代码保存在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里面要用到别的DLL里面的函数 ,是不是等将这个DLL复制到 system32下面,然后再在php.ini里面加上
extension=php_fdf.dll 这样的代码才可以?

------解决方案--------------------
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>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How many MB is 1g of memory? How many MB is 1g of memory? Mar 16, 2023 pm 04:19 PM

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 how many bytes 1MB of storage capacity is equivalent to how many bytes Mar 03, 2023 pm 05:42 PM

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 equals how many MB of memory capacity 1g equals how many MB of memory capacity Feb 03, 2023 pm 03:55 PM

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 Java uses the isLetterOrDigit() function of the Character class to determine whether a character is a letter or number Jul 24, 2023 pm 02:45 PM

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 Use java's Character.isDefined() function to determine whether a character is a defined character Jul 25, 2023 am 10:33 AM

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

Java documentation interpretation: Detailed explanation of the isAlphabetic() method of the Character class Java documentation interpretation: Detailed explanation of the isAlphabetic() method of the Character class Nov 04, 2023 am 10:05 AM

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提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

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

Use java's Character.isLetterOrDigit() function to determine whether a character is a letter or number Use java's Character.isLetterOrDigit() function to determine whether a character is a letter or number Jul 25, 2023 pm 04:22 PM

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

See all articles