Examples of strlen and mb_strlen usages in PHP _php techniques

Source: Internet
Author: User
Tags strlen

This article analyzes the usage of strlen and Mb_strlen in PHP. Share to everyone for your reference, specific as follows:

First look at the following code (file encoding UTF8):

<?php
$utf 8_string = "ABCD I you he she it";
Var_dump (strlen ($utf 8_string));
Var_dump (Mb_strlen ($utf 8_string, ' gb2312 '));
Var_dump (Mb_strlen ($utf 8_string, ' UTF8 '));
Var_dump (Mb_strlen ($utf 8_string));
>

Run Result:

int int

int 9

int 19

The 2nd parameter is the same as the original encoding of the string, and it calculates the real word in the human understanding sense. (only 1 times in Chinese text)

More interested in PHP related content readers can view the site topics: "PHP string (String) Usage summary", "PHP Array" Operation Techniques Encyclopedia, "PHP Basic Grammar Primer", "PHP Operations and Operator Usage Summary", " Introduction to PHP object-oriented programming program, "PHP Network Programming Skills Summary", "Php+mysql Database Operation Introduction" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design.

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.