色www,五月婷婷深爱五月,午夜国产一级片,色噜噜综合,国产大胸无码视频,清纯美女被操黄网站在线观看,波多野结衣av高清一区二区三区

php摘要生成函數(shù)詳解

時(shí)間:2025-11-18 12:10:09 php語言

php摘要生成函數(shù)詳解

  以前也寫過一個(gè)PHP文章摘要生成方法(函數(shù)), 不過,不怎么好用,也出現(xiàn)亂碼,現(xiàn)在再發(fā)布一個(gè),這個(gè)函數(shù)是在某開源系統(tǒng)上拆下來了,希望對(duì)大家用用。

  在使用的時(shí)候,得先把要生成摘要的內(nèi)容strip_tags()一下,當(dāng)然,你也可以把strip_tags()直接添加到函數(shù)中,我沒有搞,自己添加吧。下面是函數(shù):

  復(fù)制代碼 代碼如下:

  function cutstr($string, $length,$charset,$dot) {/pic/p>

  if(strlen($string) <= $length) {

  return $string;

  }

  $pre = chr(1);

  $end = chr(1);

  /pic/p>

  $string = str_replace(array('&', '"', '<', '>'), array($pre.'&'.$end, $pre.'"'.$end, $pre.'<'.$end, $pre.'>'.$end), $string);

  $strcut = '';

  if(strtolower($charset) == 'utf-8') {

  $n = $tn = $noc = 0;

  while($n < strlen($string)) {

  $t = ord($string[$n]);

  if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {

  $tn = 1; $n++; $noc++;

  } elseif(194 <= $t && $t <= 223) {

  $tn = 2; $n += 2; $noc += 2;

  } elseif(224 <= $t && $t <= 239) {

  $tn = 3; $n += 3; $noc += 2;

  } elseif(240 <= $t && $t <= 247) {

  $tn = 4; $n += 4; $noc += 2;

  } elseif(248 <= $t && $t <= 251) {

  $tn = 5; $n += 5; $noc += 2;

  } elseif($t == 252 || $t == 253) {

  $tn = 6; $n += 6; $noc += 2;

  } else {

  $n++;

  }

  if($noc >= $length) {

  break;

  }

  }

  if($noc > $length) {

  $n -= $tn;

  }

  $strcut = substr($string, 0, $n);

  } else {

  for($i = 0; $i < $length; $i++) {

  $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];

  }

  }

  /pic/strong>

  $strcut = str_replace(array($pre.'&'.$end, $pre.'"'.$end, $pre.'<'.$end, $pre.'>'.$end), array('&', '"', '<', '>'), $strcut);

  /pic/p>

  $pos = strrpos($s, chr(1));

  if($pos !== false) {

  $strcut = substr($s,0,$pos);

  }

  return $strcut.$dot;

  }

【php摘要生成函數(shù)詳解】相關(guān)文章:

PHP之sprintf函數(shù)用法詳解12-01

php的date()日期時(shí)間函數(shù)詳解10-16

PHP時(shí)間和日期函數(shù)詳解03-02

PHP自帶的幾個(gè)實(shí)用的數(shù)組函數(shù)詳解01-14

PHP編碼轉(zhuǎn)換函數(shù)應(yīng)用技巧詳解10-21

PHP中strtotime函數(shù)使用方法詳解10-20

PHP中生成UUID自定義函數(shù)分享01-07

PHP常用字符串相關(guān)函數(shù)詳解03-09

詳解PHP用substr函數(shù)截取字符串03-01