This article describes in detail the differences and usage of strlen, mb_strlen, substr (), mb_substr (), and mb_strcut. For more information, see.
Use the following functions to split the mb _ * string:Configuration in winInstall php_mbstring.dll ExtensionYou need to open php_mbstring.dll in php. ini.The configuration in linux can be searched online.
The Code is as follows:
Copy code
// During the test, the file encoding metho
The difference between strlen and Mb_strlen in PHP
In PHP ,strlen and Mb_strlen are functions that seek the length of a string, but for some beginners it may not be clear what the difference is if you don't read the manual.The difference between the two is explained in the following example.
First look at the example:
';//14 echo Mb_strlen ($str, ' UTF8 '). '';//6 echo Mb_strlen ($str,
In PHP, the strlen () function returns the length of the string. the strlen () function returns the length of the byte of the string. each letter, number, and symbol occupies one byte, their length is 1 strlen function description.
Int strlen (string $ string)
In this article, we can know that the
//test file encoding if UTF8
$str = ' Chinese a word 1 characters ';
Echo strlen ($str). ' Echo mb_strlen ($str, ' UTF8 '). ' Echo mb_strlen ($str, ' GBK '). ' Echo mb_strlen ($str, ' gb2312 '). ' ?>
Result Analysis: In strlen calculations, the Chinese character for a UTF8 is 3 lengths, so the length of the word "1" is 3*4+2=14, and when Mb_strlen is calculated, the selected inner code
The difference between strlen and Mb_strlen in PHP
In PHP ,strlen and Mb_strlen are functions that seek the length of a string, but for some beginners it may not be clear what the difference is if you don't read the manual.The difference between the two is explained in the following example.
First look at the example:
';//14 echo Mb_strlen ($str, ' UTF8 '). '';//6 echo Mb_strlen ($str,
int strlen (String $string)int strlen (string $string) Gets the length of the string $string if the [byte] length of the given string succeeds, and returns 0 if $string is empty.PHP$str 1= "ABCdef";//Output 6 $str 2= "AB CD";//Output 7, note, opening, ending, middle space $STR 3= "Hello China";//output 12, but varies, related to the character encoding used by the system $STR 4= "Hello, China";//out
is the internal implementation of the count (array) and strlen (string) of PHP a direct display of a length variable, or how many elements are there in a number of times?It's about my understanding of the efficiency of these 2 functions.I hope that Gao can from the C source of PHP to talk about. There is no source code to see the source know that said also OK.1. When count is executed, is there a number of "statistics per" child elements behind it?2,
In PHP, strlen and Mb_strlen are functions that ask for string lengths, but for some beginners, it may not be clear what the difference is if you don't read the manual.Here's an example to explain the difference between the two.
First look at the example:
Result analysis: In strlen calculation, to treat a UTF8 Chinese character is 3 length, so the length of "A word 1" is 3*4+2=14, in Mb_strle
Today I saw an algorithm for the topic, said to be merged into two ordered arrays, in an orderly manner.
Look at the thought is very simple, take for granted began to knock on the program, but found a lot of small problems, these are the basis ah, prominent is the sizeof () problem.
sizeof () Gets the length of the occupied byte of a type (I actually used to get the length of the array)
Strlen gets the length of the string (I'm still used to get
This article analyzes the usage of strlen and Mb_strlen in PHP. Share to everyone for your reference, specific as follows:
First look at the following code (file encoding UTF8):
Run Result:
int int
int 9
int 19
The 2nd parameter is the same as the original encoding of the string, and it calculates the real word in the human understanding sense. (only 1 times in Chinese text)
More interested in PHP related content readers can vie
Description of the Strlen function.
int strlen (String $string)
In this article, we can know that the strlen function is defined by the Zend engine. The definition of a function can be viewed here.
The source code for the function is also given here:
Zend_function (strlen) { char *s1; int S1_len; if (Zend_par
This article mainly introduces the PHP built-in function strlen and mbstring extension function Mb_strlen difference, has a certain reference value, now share to everyone, the need for friends can refer to
#EXAMPLE
$str _uncode = "Simplified Chinese Chinese (Simplified)";//statistical string length echo strlen ($str _uncode). '
Results Analysis:
Strlen a Chine
In PHP, strlen and Mb_strlen are functions that seek the length of a string, but for some beginners it may not be clear what the difference is if you don't read the manual.
The difference between the two is explained in the following example.
First look at the example:
';//14 Echo Mb_strlen ($str, ' UTF8 '). '';//6 Echo Mb_strlen ($str, ' GBK '). '';//8 Echo Mb_strlen ($str, ' gb2312 '). '
Results analysis: In the
The strlen function in glib2.0 is defined as follows:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--># Include
Size_tStrlen (const char * str){Int cnt;
Asm ("cld \ n"/* Search forward. Clear direction position *//* Some old versions of gas need 'repne 'instead of 'repnz '.*/// ECX! If it is set to 0 and ZF is set to 0, the loop continues."Repnz \ n"/* Look for a zero byte .*/// AL-(ES: [EDI])"Scasb"/
int x = 2;char * str = "ABCD"; int y = (X-strlen (str))/3;printf ("%d\n", y); Here the strlen () return value is unsigned, and the (X-strlen (str)) is coerced to an unsigned number, i.e. the complement of 2 is divided by 3 and the result is 1431655764; if you replace (x-(int) strlen (str))/3 you can get 0..... From a
Using the differences between the above characters and the English language, we can use the Mb_strlen function and the strlen function to calculate two sets of length numbers, and then do the operation according to the law to determine the type of string.
Let's talk about Strlen and Mb_strlen is a function of string length
The code is as follows
Copy Code
How the file is encode
(1) When the strlen function is used to calculate the length of a string, the strlen result value does not contain '\ 0. When sizeof calculates the length of a string, its result value includes '\ 0 '.
(2) If sizeof is used as an array, only the size of the static array can be measured, and the size of the dynamically allocated or external array cannot be detected.
(3) sizeof is a keyword rather than a fu
Programmer --- C language details 26 (boolean type, continue details in C language, sizeof example, strlen example)Main Content: boolean type, continue details in C language, sizeof example, strlen exampleI. boolean type
Many people may not know that the C language already has the Boolean Type: Starting from the C99 standard, the type name is "_ Bool"
Before the C99 standard, we often mimic and define the b
Label: style blog color Io AR for SP Div on
1 #include
Compilation error:
test_scanf.c: In function ‘main’:test_scanf.c:7:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=] printf("%d\n", sizeof(temp)); ^test_scanf.c:8:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ [-Wformat=] printf("%d\n", strlen(temp)); ^
Sizeof () and
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.