PHP returns the length of the string function strlen ()

Source: Internet
Author: User

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.

Related Article

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.