<?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: