In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.