Get the App
SLTechnology News&Howtos  ›  Development  › 

How does php intercept the replacement string according to the number of words

Shulou Source: shulou.com Published: 2022-06-03 17:32:53 10月22日 Update

This article mainly explains "php how to intercept the replacement string according to the number of words", the content of the explanation in the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "php how to intercept replacement string according to the number of words" bar!

1. Use the "function substr_format () {...}" method to intercept and replace.

2. Use the "function cut_string ($str, $len) {...}" method to intercept and replace.

Example

Function cut_string ($str, $len) {/ / check length if (mb_strwidth ($str, 'UTF-8') 127? 2: 1 * if ($tlen + $chrLen > $len) break;$tstr. = $chr;$tlen + = $chrLen;$i + +;} if ($tstr! = $str) {$tstr. ='...';} return $tstr } Thank you for reading, the above is the content of "how php intercepts the replacement string according to the number of words". After the study of this article, I believe you have a deeper understanding of how php intercepts the replacement string according to the number of words, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Number of words characters strings learning content methods examples that is ideas situations articles more knowledge knowledge points articles follow length problems practice push Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Huawei MySQL Shulou Tech Info Redmi