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 strlen function is defined by Zend Engine. The function definition can be viewed here.
The source code of the function is also provided here:
ZEND_FUNCTION (strlen) {char * s1; int s1_len; if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, "s", & s1, & s1_len) = FAILURE) {return ;} RETVAL_LONG (s1_len );}
As mentioned in this article, this function is very simple and does not need further explanation. This article also introduces the zend_parse_parameters function. I am stupid, so I want to understand how the zend_parse_parameters function returns the variable length.
In the zend_parse_arg_impl function, the parameter is resolved. let's continue to look at the branch of case's. This branch is used to parse string variables.
Int * pl = va_arg (* va, int *); is the definition of the string length variable.
You can see the value assignment statement for the pl variable: * pl = Z_STRLEN_PP (arg );.
The Z_STRLEN_PP macro is defined in the zend_operators.h file:
# Define Z_STRLEN_PP (zval_pp) Z_STRLEN (** zval_pp)
Let's continue with the definition of Z_STRLEN macro, # define Z_STRLEN (zval). value. str. len. From this we can know that the strlen function is implemented by directly returning the len attribute of str in the zval struct.