中文截取 modifier.cn_truncate.PHP
代码如下:
function smarty_modifier_cn_truncate($string,$strlen = 20,$etc = '...',
$keep_first_style = false)
{
$strlen = $strlen*2;
$string = trim($string);
if ( strlen($string) <= $strlen ) {
return $string;
}
$str = strip_tags($string);
$j = 0;
for($i=0;$i<$strlen;$i++) {
if(ord(substr($str,$i,1))>0xa0) $j++;
}
if($j%2!=0) $strlen++;
$rstr=substr($str,$strlen);
if (strlen($str)>$strlen ) {$rstr .= $etc;}
if ( $keep_first_style == true && ereg('^<(.*)>$',$string) ) {
if ( strlen($str) <= $strlen ) {
return $string;
}
$start_pos = strpos($string,substr($str,4));
$end_pos = strpos($string,-4));
$end_pos = $end_pos+4;
$rstr = substr($string,$start_pos) . $rstr . substr($string,$end_pos,strlen($string));
}
return $rstr;
}
$keep_first_style = false)
{
$strlen = $strlen*2;
$string = trim($string);
if ( strlen($string) <= $strlen ) {
return $string;
}
$str = strip_tags($string);
$j = 0;
for($i=0;$i<$strlen;$i++) {
if(ord(substr($str,$i,1))>0xa0) $j++;
}
if($j%2!=0) $strlen++;
$rstr=substr($str,$strlen);
if (strlen($str)>$strlen ) {$rstr .= $etc;}
if ( $keep_first_style == true && ereg('^<(.*)>$',$string) ) {
if ( strlen($str) <= $strlen ) {
return $string;
}
$start_pos = strpos($string,substr($str,4));
$end_pos = strpos($string,-4));
$end_pos = $end_pos+4;
$rstr = substr($string,$start_pos) . $rstr . substr($string,$end_pos,strlen($string));
}
return $rstr;
}
modifier.ubb.PHP
代码如下:
PHP
function smarty_modifier_ubb($str) {
$ubbs['quote'][0] = '/\[quote\](.*?)\[\/quote\]/s';
$ubbs['quote'][1] = '
$ubbs['b'][0] = '/\[b\](.*?)\[\/b\]/s';
$ubbs['b'][1] = '\1';
$ubbs['i'][0] = '/\[i\](.*?)\[\/i\]/s';
$ubbs['i'][1] = '\1';
$ubbs['u'][0] = '/\[u\](.*?)\[\/u\]/s';
$ubbs['u'][1] = '\1';
$ubbs['li'][0] = '/\[li\](.*?)\[\/li\]/s';
$ubbs['li'][1] = '\1 ';
$ubbs['img'][0] = '/\[img\](.*?)\[\/img\]/s';
$ubbs['img'][1] = '$ubbs['img2'][0] = '/\[img=([^,]+),([^\]]+)\](.*?)\[\/img\]/s';
$ubbs['img2'][1] = '$ubbs['url'][0] = '/\[url\](.*?)\[\/url\]/s';
$ubbs['url'][1] = '';
$ubbs['url2'][0] = '/\[url=([^\]]+)\](.*?)\[\/url\]/s';
$ubbs['url2'][1] = '';
$ubbs['email'][0] = '/\[email=([^\]]+)\](.*?)\[\/email\]/s';
$ubbs['email'][1] = '';
$ubbs['qq'][0] = '/\[qq\]([0-9]{5,10})\[\/qq\]/s';
$ubbs['qq'][1] = '';
$ubbs['color'][0] = '/\[color=([^\]]+)\](.*?)\[\/color\]/s';
$ubbs['color'][1] = '$ubbs['font'][0] = '/\[font=([^\]]+)\](.*?)\[\/font\]/s';
$ubbs['font'][1] = '$ubbs['size'][0] = '/\[size=([0-9]+)\](.*?)\[\/size\]/s';
$ubbs['size'][1] = '$ubbs['sizept'][0] = '/\[size=([0-9,pt]+)\](.*?)\[\/size\]/s';
$ubbs['sizept'][1] = '$ubbs['align'][0] = '/\[align=([^\]]+)\](.*?)\[\/align\]/s';
$ubbs['align'][1] = '
function smarty_modifier_ubb($str) {
$ubbs['quote'][0] = '/\[quote\](.*?)\[\/quote\]/s';
$ubbs['quote'][1] = '
引用:';
\1
$ubbs['b'][0] = '/\[b\](.*?)\[\/b\]/s';
$ubbs['b'][1] = '\1';
$ubbs['i'][0] = '/\[i\](.*?)\[\/i\]/s';
$ubbs['i'][1] = '\1';
$ubbs['u'][0] = '/\[u\](.*?)\[\/u\]/s';
$ubbs['u'][1] = '\1';
$ubbs['li'][0] = '/\[li\](.*?)\[\/li\]/s';
$ubbs['li'][1] = '
$ubbs['img'][0] = '/\[img\](.*?)\[\/img\]/s';
$ubbs['img'][1] = '$ubbs['img2'][0] = '/\[img=([^,]+),([^\]]+)\](.*?)\[\/img\]/s';
$ubbs['img2'][1] = '$ubbs['url'][0] = '/\[url\](.*?)\[\/url\]/s';
$ubbs['url'][1] = '';
$ubbs['url2'][0] = '/\[url=([^\]]+)\](.*?)\[\/url\]/s';
$ubbs['url2'][1] = '';
$ubbs['email'][0] = '/\[email=([^\]]+)\](.*?)\[\/email\]/s';
$ubbs['email'][1] = '';
$ubbs['qq'][0] = '/\[qq\]([0-9]{5,10})\[\/qq\]/s';
$ubbs['qq'][1] = '';
$ubbs['color'][0] = '/\[color=([^\]]+)\](.*?)\[\/color\]/s';
$ubbs['color'][1] = '$ubbs['font'][0] = '/\[font=([^\]]+)\](.*?)\[\/font\]/s';
$ubbs['font'][1] = '$ubbs['size'][0] = '/\[size=([0-9]+)\](.*?)\[\/size\]/s';
$ubbs['size'][1] = '$ubbs['sizept'][0] = '/\[size=([0-9,pt]+)\](.*?)\[\/size\]/s';
$ubbs['sizept'][1] = '$ubbs['align'][0] = '/\[align=([^\]]+)\](.*?)\[\/align\]/s';
$ubbs['align'][1] = '
$ubbs['media'][0] = '/\[media\](.*?)\[\/media\]/s';
$ubbs['media'][1] = '
$ubbs['media'][1] = '