PHP intercepts utf8 strings without distinguishing between Chinese and English

<?php
header('Content-Type: text/html; charset=utf-8');
//Intercept utf8 string
function utf8Substr($str='', $start=0, $len=10)
{
    return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$start.'}'.
        '((?: [\ x00- \ x7F] | [\ xC0- \ xFF] [\ x80- \ xBF] +) {0,'. $ len. '}). * # s',
        '$1',$str);
}
echo utf8Substr('Who asks you to read, the fragrance floats when the water falls.',8,2),PHP_EOL;
echo utf8Substr('Wu Zheran onestopweb');

 

Effect picture:

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326779208&siteId=291194637