The usual functions for calculating string lengths in PHP are: strlen and Mb_strlen. When the word embox is an English character, the two are the same. Here the main comparison, the Chinese and English mixed in the time, two calculation results.
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 th
Common functions used in php to calculate the string length include strlen and mb_strlen. when the characters are all English characters, the two are the same. Here we will mainly compare the two calculation results when mixing Chinese and English. In PHP, strlen and mb_strlen are functions used to evaluate the string length. However, for some beginners, if they do not read the manual, they may not know the
Common functions used in php to calculate the string length include strlen and mb_strlen. When the characters are all English characters, the two are the same. Here we will mainly compare the two calculation results when mixing Chinese and English.
Let's look at an example:
Copy codeThe Code is as follows:// During the test, the file encoding method is UTF8.$ Str = 'Chinese character a 1 ';Echo strlen ($ st
Instance
The function returns the length of the string "Hello":
Definition and usage
The strlen () function returns the length of the string.
Grammar
Strlen (String)
Parameters
Describe
String
Necessary. Specifies the string to check.
technical details
return value:
php version:
4+
update log:
More e
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
The differences between strlen and mb_strlen in PHP are described in detail in
PHPMedium,
StrlenAnd
Mb_strlenIt is a function to evaluate the length of a string, but for some beginners, if you do not read the manual, you may not know the difference.
The following is an example to illustrate the differences between the two.
First look at the example:
// During the test, the file encoding method is UTF8.
$ Str = 'Chinese character a 1 ';
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:
How to encode a file when testing if UTF8
$str =' Chinese a word 1 characters ';
echo strlen ($str).' //14
Echo Mb_strlen ($s
Example 1: Char ss [100] = "0123456789 ";
The result of sizeof (SS) is 100. SS indicates the pre-allocated size in the memory, which is 100*1;
The strlent (SS) returns 10. Its internal implementation is to calculate the length of the string in a loop until "\ 0.
Example 2: int ss [100] = "0123456789 ";
The result of sizeof (SS) is 400. SS indicates the memory size, which is 100*4;
Strlen (SS) error. The strlen
Compare strlen and Mb_strlenWhen the word Fu Quan is an English character, the two are the same. Here the main comparison, in Chinese and English mixed row, two results. (Encoding is UTF8 when testing)
Copy Code code as follows:
$str = ' Chinese a word 1 characters ';
echo strlen ($STR);
echo ' Echo Mb_strlen ($str, ' UTF8 ');
Output results
14
6
?>
Result analysis: In
[Original]
Char STR [20] = "0123456789 ";Int A = strlen (STR);/* A = 10; strlen calculates the length of the string, ending with \ 0. Int B = sizeof (STR);/* B = 20; sizeof calculates the memory space occupied by the allocated array STR [20, it is not affected by the content stored in it ================================================ ========================================================== =============
I officially started learning PHP today, but I accidentally discovered something that requires special attention when using PHP. For example: htmlmetacharsetutf-8body? Php $ name; print name:. strlen ($ name );? The output result of the bodyhtml code is: The name length is: 6.
I officially started learning PHP today, but I accidentally discovered something that requires special attention when using PHP. Example: htmlmeta charset = utf-8body? Php $ nam
The code is as follows:---------------------------------#include #include #include int Main (){ Char a[1000]; int i = 0; for (i = 0; i {A[i] = -1-i;printf ( "a%d =%d\n", I,a[i]);}printf ( "strlen (a) =%d", Strlen (a)); printf ( printf ( sizeof sizeof ( A[0]); return 0;}------------------------------------------results of the program execution: a0 =-1 a1 = -2 Until a127 = 128 then a
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
1. strlen detects '/0' and strlen is a function. In this sense, strlen has no practical value for uninitialized or assigned values.
Sizeof is an operator that is only interested in the type of a variable. The value of a variable has no effect on it.
Char Buf [108];Memset (BUF, 0,108 );Printf ("strlen (BUF) is % d/N",
Strlen () and strcpy () functions, strlenstrcpy Functions
The difference between strlen () and strcpy () functions. One is to return the length of a C-style string, and the other is to copy a C-style string, the two functions are different. In addition, they have some minor differences: The result returned by strlen ("hello") is 5, which isDoes not contain'\ 0',
1, compile-time calculation operator sizeof, available types or variables to do parameters, calculate the size of memory consumption. If the type must be bracketed after sizeof, the variable name may not be bracketed. sizeof (x) can be used to define array dimensions such as:
Copy Code code as follows:
printf ("%d\n", sizeof (short));
The result of the output is the length of the short integer 2. When you use a struct type or variable as a parameter, the sizeof returns
Definitions and usage
The strlen () function returns the length of the string.
Grammar
strlen (String) parameter descriptionString required. Specify the string to check.
The reference to the Mb_strlen () function is also the same.
Example
The code is as follows
Copy Code
$str = ' Chinese a word 1 characters ';echo strlen ($STR);e
Tags: inux BSP long resolved otherwise SRE is fine style1. PrefaceMany friends in the development of network programming may have encountered such a problem, in the process of receiving binary stream data, using the Strlen library function to getThe binary data length is not accurate. Why?? First, the strlen is used for the statistical length of the string, not the binary stream data, so theGetting the bina
Test interview 5 implement the C library function strlen
This is a very simple problem.
Strlen (str) is used to calculate the total number of characters in str.
When storing strings, A '\ 0' is added to the end of the last character '.
Use this to write your own strlen function.
Source code:
# Include
# Include
Int MyStrlen (char str []) {if (str = N
1. The result type of the sizeof operator is size_t. In the header file, typedef is of the unsigned int type. This type ensures that it can accommodate the maximum object size.
2. sizeof is an operator (C ++ keyword) and strlen is a function.
3. sizeof can be a type parameter. strlen can only be a char * parameter and must end with "\ 0. Sizeof can also be used as a parameter using a function, for example:
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.