Introduction to intercept string function in Thinkphp template

  • 2021-06-29 10:34:40
  • OfStack

There are many functions to intercept strings in php, but php functions can also be used directly in thinkphp. This paper gives you a brief introduction of the specific usage of intercept strings in thinkPHP templates, hoping to help you.

The following forms can be used for English characters:


{$vo.title|substr=0,5}

If the Chinese character thinkphp provides msubstr, the usage is as follows:


function msubstr($str, $start=0, $length, $charset= " utf-8 ″ , $suffix=true)// Use as follows
{$vo.title|msubstr=5,5,'utf-8 ' ,true}

The msubstr function is described as follows:

msubstr ($str, $start=0, $length, $charset="utf-8", $suffix=true)
$str: String to intercept
$start=0: Start position, default start from 0
$length: intercept length
$charset="utf-8": Character encoding, default UTF-8
$suffix=true: Whether to display ellipsis after truncated characters, default true display, false does not display

More readers interested in thinkPHP-related content can view this site's topics: Introduction to ThinkPHP, Summary of thinkPHP Template Operation Skills, Summary of ThinkPHP Common Methods, Introduction to smarty Templates and Technical Summary of PHP Templates.

I hope that the description in this paper will be helpful to everyone's PHP program design based on the ThinkPHP framework.


Related articles: