阅读:3012回复:0
joomla用php 引言截断函数,符合UTF-8编码
终于搞成了,这个函数库可通用,另外过滤掉
、' '、<img /> 、 、空白这些标签,并按照utf-8编码计算字节数! function trimString($content,$len){ $content = preg_replace("']*?/|hr[^/>]*?/|/(div|h[1-6]|li|p|td))>'si", '', $content); $content = preg_replace( '/]*>/is', '', $content); $content = preg_replace("' 'si", '', $content); $content = preg_replace("' 'si", '', $content);//本行代码复制时请注意nbsp部分,与&之间空格要去掉,这里只是为了正常显示nbsp; $content = mb_strimwidth($content,0,$len,'...','utf-8'); $content = strip_tags($content); return $content; } |
|