100 evaluate the length of the detection string $ str [0] = & quot; 123asd Hello [haha] & quot; $ str [1] = & quot; 123asd Hello [] & quot; // A Chinese character (UTF-8 encoded) symbol [here the word and the symbol outside are counted as one character] & nbsp; then, the calculated length is $ str [0] and $ str [1], which is 100 points.
$ Str [0] = "123asd Hello [haha]"
$ Str [1] = "123asd Hello [Hi!]"
// One Chinese character and one character (UTF-8 encoding) symbol [here the word and the symbol outside are counted as one character]
Then calculate the length
The result is $ str [0] and $ str [1] with a length of 9.
It is best to write a function. Thank you.
------ Solution --------------------
I didn't quite understand the subject, but there was a function at hand.
PHP code
/*** Get the utf8 length * @ author mu_rain * @ param String $ str * @ return Int */static function strlen_utf8 ($ str) {$ I = 0; $ count = 0; $ len = strlen ($ str); while ($ I <$ len) {$ chr = ord ($ str [$ I]); $ count ++; $ I ++; if ($ I >=$ len) break; if ($ chr & 0x80) {$ chr <= 1; while ($ chr & 0x80) {$ I ++; $ chr <= 1 ;}} return $ count ;}
------ Solution --------------------
PHP code
Function myLen ($ str, $ startTag = '[', $ endTag = ']', $ encoding = 'utf-8') {$ st = preg_quote ($ startTag ); $ et = preg_quote ($ endTag); return mb_strlen (preg_replace ("# {$ st} [^ {$ et}] * {$ et }#","~ ", $ Str), $ encoding);} echo myLen (" 123asd Hello [haha] "); // 9
------ Solution --------------------
A bunch of string functions are provided, which is slow to use.
PHP code