The code is as follows:
/** * @param $string * @param $from starting from 0 ... * @param null $length * @r Eturn String * C_SUBSTR ("Give Me a little", $from =0, 9) >> give me A * C_SUBSTR ("Give Me a little", $from =1, 9) >> I * c_subst R ("Give Me a little", $from =2, 9) >> I * C_SUBSTR ("Give Me a little", $from =3, 9) >> me a little * *Private functionc_substr($string, $from=0, $length = null){//Required field checkif(!isset($string)||!isset($from)||$from<0){return''; }//Get string length$strLen= Strlen ($string);//Set length to string if no length is setif($length==NULL){$length=$strLen; }//Determine if the string length is less than or equal to $length, then return the string directlyif($from==0&&$length>=$strLen){return$string; }$subLen=$length+$from;$rtnStr="";//Start intercept string//In order to intercept the complete, you need to traverse from the beginning for($i=0;$i<$subLen&&$i<$strLen;$i++){//To determine if it is Chinese if it is not very long, and then cut back 2 bytesif(Ord ($string[$i]) >0xa0){if($i+2<$subLen&&$i+2<$strLen){$rtnStr.=$string[$i].$string[$i+1].$string[$i+2];/** * If "give me a little" * intercept 9 bytes from position 0, just get "give me One" * intercept 9 bytes from position 1, then only get "I "* Intercept 9 bytes from position 2, get only" i "* intercept 9 bytes from position 3, then get only" me "* the following if is to skip the beginning not Full character * /if($i<$from){$rtnStr=""; }$i+=2; }Else{return$rtnStr; } }//EnglishElse{$rtnStr.=$string[$i]; } }return$rtnStr; }
Copyright Notice: Reproduced when the mention of me on the line ...
The above describes the PHP interception in English, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.