SoFunction
Updated on 2025-03-03

PHP simple intercepting string code example

This article example describes the method of php to simply intercept strings. Share it for your reference, as follows:

//Search summarypublic static function mbsubstr($str){
  $strleng = mb_strlen($str,"utf8");
  $mbstr = mb_substr($str,0,140,'utf8');
  $strdstr = mb_substr($str,140,$strleng,'utf8');
  $strlengs = mb_strlen($strdstr,'utf8');
  $strc = "";
  for($i=0;$i<$strlengs;$i++){
    $strn = mb_substr($strdstr,$i,1,'utf8');
    if($strn == "。" || $strn == "?" || $strn == "!"){
      break;
    }
    $strc .= $strn;
  }
  $strd = $mbstr.$strc;
  //echo $strleng."@".mb_strlen($strd,'utf8')."@".$strd."<br>";
  return $strd;
}

For more information about PHP related content, please check out the topic of this site:Summary of usage of php strings》、《Complete collection of PHP array (Array) operation techniques》、《Introduction to PHP basic syntax》、《Summary of PHP operations and operator usage》、《PHP object-oriented programming tutorial》、《Summary of PHP network programming skills》、《PHP+mysql database operation tutorial"and"Summary of common database operation techniques for php

I hope this article will be helpful to everyone's PHP programming.