Home > php教程 > php手册 > body text

php中文汉字截取函数

WBOY
Release: 2016-06-06 19:46:37
Original
958 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 功能:中文汉字截取函数 //$in要截取的字符串, $num要截取的长度, 返回截取的字符串 public function substrgb($in,$num) { //$num=16; $pos=0; $bytenum=0; $out=""; while($num){ $c=mb_subs

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  功能:中文汉字截取函数

  //$in要截取的字符串, $num要截取的长度, 返回截取的字符串

  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;

  }

php中文汉字截取函数

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!