php在字符断点处截断文字的代码一例
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Libérer: 2016-07-25 08:58:50
original
1003 Les gens l'ont consulté
-
-
//所谓断字 (word break),即一个单词可在转行时断开的地方。这一函数将在断字处截断字符串。
- // Please acknowledge use of this code by including this header.
- function myTruncate($string, $limit, $break=".", $pad="...") {
- // return with no change if string is shorter than $limit
- if(strlen($string) return $string;
- // is $break present between $limit and the end of the string?
- if(false !== ($breakpoint = strpos($string, $break, $limit))) {
- if($breakpoint $string = substr($string, 0, $breakpoint) . $pad;
- }
- }
- return $string;
- }
- /***** Example ****/
- $short_string=myTruncate($long_string, 100, ' ');
- ?>
复制代码
|
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers articles par auteur
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11