Instance
The function returns the length of the string "Hello":
<?phpecho strlen ("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 examples
Example 1
Returns the length of the string "Hello World":
<?phpecho strlen ("Hello world!");? >
In PHP, the function strlen () returns the length of the string. The function prototypes are as follows:
int strlen (string string_input);
The parameter string_input is the string to be processed.
The strlen () function returns the byte length of a string, with an English letter, a number, and a variety of symbols representing one byte, each of which has a length of 1. A noon character occupies two bytes, so the length of a noon character is 2. For example
<?php Echo strlen ("www.sunchis.com"); echo strlen ("Tri-Knowledge Development Network");?>
"Echo strlen (" www.sunchis.com "); Operation Result: "Echo strlen (" Three-Knowledge Development Network "); Running results: 15
Here's a question, does a Chinese character account for 2 bytes? "Three-knowledge Development network", is clearly five characters, the results of the operation is 15?
The reason is here: strlen () calculation, for a UTF-8 of Chinese characters, it will be treated as a length of.