label: PHP,substr,mb_substr, Garbled
Usually we will use substr to intercept the string. If all the strings in English are normal, but there are other words, it will occasionally produce garbled characters after interception. In fact, because a character stores more than one byte when the character is stored, the interception of the substr function is intercepted by byte, so when we cut off multiple bytes of a character, it will cause garbled characters. In fact, the mb_substr function in PHP is for this scenario, it supports string interception according to string encoding.
mb_substr($str, $start, $length, $encoding)
mb_substr('XXXXXXXX', 0, 4, 'utf-8');
Of course, in addition to the string interception accident, the length of the string is also a function that supports the encoding format.