Home >Backend Development >PHP Tutorial >PHP Chinese character interception function_PHP tutorial
Chinese character interception function
//The string to be intercepted, $num the length to be intercepted, return the intercepted string
public function substrgb($in,$num) { //$num=16; $pos=0; $bytenum=0; $out=""; while($num){ $c=mb_substr($in,$pos,1,"euc-jp"); if($c=="n") break; if(strlen($c)==1){ $pos++; $bytenum++; if($bytenum>$num) break; $out.=$c; } else { $pos++; $bytenum=$bytenum+2; if($bytenum>$num) break; $out.=$c; } } return $out; }