Simple Introduction to strlen functions in PHP

Source: Internet
Author: User
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.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.