"PHP" PHP truncation function mb_substr of

  • 2020-05-30 19:46:39
  • OfStack

Function: mb_substr( $str, $start, $length, $encoding )

$str, need to truncate the string
$start, where the truncation begins
$length, length (note that this is different from mb_strimwidth, where 1 represents 1 Chinese character)
$encoding, code, I'm going to say utf-8

Example: truncate the title of the article and limit it to 15 words
 
<?php echo mb_substr(get_the_title(), 0, 15,"utf-8"); ?> 

Related articles: