Determines whether the input is a pure number, English or Chinese character.
Using the mb_strlen and strlen functions of php, you can easily know whether the string is composed of English letters, English letters and Chinese characters, or pure Chinese characters. A brief description is as follows (the preceding example program). 1. if the length returned by strlen is the same as that calculated by the current encoding, it can be determined that it is a pure English string. 2. if the length of the character returned by strlen is different from that calculated by mb_strlen based on the current encoding, and the return value of strlen is the same as that of mb_strlen, after which 0 is obtained, it can be regarded as a Chinese character string. 3. if the length of the character returned by strlen is different from that calculated by mb_strlen based on the current encoding, and the return value of strlen is the same as that of mb_strlen, the return value is not 0 After remainder, it can be determined to be an English-Chinese string.
- /********
- Determines whether the input is a pure number, English or Chinese character.
- Using the mb_strlen and strlen functions of php, you can easily understand the composition of strings.
- Whether it is English, English-Chinese, or pure Chinese characters. A brief description is as follows (the above example program)
- 1. if the length of the character returned by strlen and mb_strlen are calculated as the current encoding
- Can be determined to be a pure English string.
- 2. if the length of the character returned by strlen is inconsistent with that calculated by the current encoding,
- And the strlen return value is the same as the mb_strlen return value. after the remainder is obtained, 0 can be judged as a Chinese character string.
- 3. if the length of the character returned by strlen is inconsistent with that calculated by the current encoding,
- The return value of strlen is equal to that of mb_strlen. if the return value is not 0 after the remainder is obtained, it can be regarded as a string of English-Chinese mixture.
- *
- *****************/
- $ Str = "456abc ";
- $ X = mb_strlen ($ str, 'gb2312 ');
- $ Y = strlen ($ str); echo "------ 456abc ----
";
- Echo "$ x ".'
';
- Echo "$ y ".'
';
- $ Str = "456 I am a chinese abc
";
- $ X = mb_strlen ($ str, 'gb2312 ');
- $ Y = strlen ($ str );
- Echo "------ 456 I am a chinese abc ----
";
- Echo "$ x ".'
'; Echo "$ y ".'
';
- $ Str = "I am a chinese and I love my motherland ";
- $ X = mb_strlen ($ str, 'gb2312 ');
- $ Y = strlen ($ str );
- Echo "------ I am a chinese, I love my motherland ----
"; Echo" $ x ".'
';
- Echo "$ y ".'
'; $ Str = "I ";
- $ X = mb_strlen ($ str, 'gb2312 ');
- $ Y = strlen ($ str );
- Echo "------ I ----
"; Echo" $ x ".'
';
- Echo "$ y ".'
';
- $ Str = "my AB ";
- $ X = mb_strlen ($ str, 'gb2312 ');
- $ Y = strlen ($ str );
- Echo "------ I AB ----
"; Echo" $ x ".'
'; Echo "$ y ".'
';
- ?>
|