PHP function to display limited words from a string.
PHP function to display limited words from a string. [代码片段(15行)]
function words_limit( $str, $num, $append_str='' ){ $words = preg_split( '/[\\s]+/', $str, -1, PREG_SPLIT_OFFSET_CAPTURE ); if( isset($words[$num][1]) ){ $str = substr( $str, 0, $words[$num][1] ).$append_str; } unset( $words, $num ); return trim( $str );> } echo words_limit($yourString, 50,'...'); or echo words_limit($yourString, 50); //该片段来自于http://outofmemory.cn
- 上一篇:php 连接 MySQL 数据库
- 下一篇:php 计算日期差异
精彩图集
精彩文章