文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>PHP中字符串截断函数

PHP中字符串截断函数

时间:2005-08-05  来源:manbuzhe0301

function trimBody($theText, $lmt=500, $s_chr=" ", $s_cnt=2)

一个实现字符串 截断的函数。

function trimBody($theText, $lmt=500, $s_chr=" ", $s_cnt=2) {
 $pos = 0;
 $trimmed = FALSE;
 for ($i = 1; $i <= $s_cnt; $i++) {
  if ($tmp = strpos($theText, $s_chr, $pos+1)) {
   $pos = $tmp;
   $trimmed = TRUE;
  } else {
  $pos = strlen($theText) - 1;
  $trimmed = FALSE;
  break;
  }
 }
 $theText = substr($theText, 0, $pos);
 if (strlen($theText) > $lmt) {
  $theText = substr($theText, 0, $lmt);
  $theText = substr($theText, 0, strrpos($theText," "));
  $trimmed = TRUE;
 }
 if ($trimmed) $theText .= "...";
 return $theText;
}

相关阅读 更多 +
排行榜 更多 +
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

飞行射击 下载
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

飞行射击 下载
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

飞行射击 下载