Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does php determine how many bits a string is?

2025-12-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to judge how many characters a string is in php". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Php to determine how many bits a string is: 1, the use of strlen () function, you can get the number of characters of the English string, syntax "strlen ($str)"; 2, the use of mb_strlen () function, syntax "mb_strlen ($str, $encoding)".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

How can php tell how many bits a string is?

Determine how many bits the string is, that is, how many characters the string has, that is, get the length of the string.

Two built-in functions are provided in php to get the string length.

Strlen (): get the length of an English string

In the strlen () function, numbers, English, decimal points, underscores and spaces account for one character length, while one GB2312-encoded Chinese character occupies two character length and one UTF-8-encoded Chinese character occupies three character length.

Mb_strlen (): gets the length of a Chinese or English string

In the mb_strlen () function, no matter Chinese characters, or English, numbers, decimal points, underscores and spaces, occupy only one character length.

1. Use the strlen () function

2. Use the mb_strlen () function

Mb_strlen ($str, $encoding) can return the corresponding number of characters by setting the character encoding, which well deals with the length of the Chinese string.

The return value of the mb_strlen () function is the number of characters contained in the string $str with $encoding encoding, or false if $encoding is invalid.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

  • How to use css to realize wavy line and cube

    This article is about how to use css to implement wavy lines and cubes. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look. 1.css realizes the wavy line html

    12
    Report