当前位置:Gxlcms > PHP教程 > phpsmarty函数扩展_php模板

phpsmarty函数扩展_php模板

时间:2021-07-01 10:21:17 帮助过:10人阅读

中文截取 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,https://www.gxlcms.com/1))>0xa0) $j++;
}
if($j%2!=0) $strlen++;
$rstr=substr($str,0,$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,0,4));
$end_pos = strpos($string,substr($str,-4));
$end_pos = $end_pos+4;
$rstr = substr($string,0,$start_pos) . $rstr . substr($string,$end_pos,strlen($string));
}
return $rstr;
}

modifier.ubb.php
代码如下:

function smarty_modifier_ubb($str) {
$ubbs['quote'][0] = '/\[quote\](.*?)\[\/quote\]/s';
$ubbs['quote'][https://www.gxlcms.com/1] = '
引用:
\https://www.gxlcms.com/1
';
$ubbs['b'][0] = '/\[b\](.*?)\[\/b\]/s';
$ubbs['b'][https://www.gxlcms.com/1] = '\https://www.gxlcms.com/1';
$ubbs['i'][0] = '/\[i\](.*?)\[\/i\]/s';
$ubbs['i'][https://www.gxlcms.com/1] = '\https://www.gxlcms.com/1';
$ubbs['u'][0] = '/\[u\](.*?)\[\/u\]/s';
$ubbs['u'][https://www.gxlcms.com/1] = '\https://www.gxlcms.com/1';
$ubbs['li'][0] = '/\[li\](.*?)\[\/li\]/s';
$ubbs['li'][https://www.gxlcms.com/1] = '
  • \https://www.gxlcms.com/1
  • ';
    $ubbs['img'][0] = '/\[img\](.*?)\[\/img\]/s';
    $ubbs['img'][https://www.gxlcms.com/1] = '';
    $ubbs['img2'][0] = '/\[img=([^,]+),([^\]]+)\](.*?)\[\/img\]/s';
    $ubbs['img2'][https://www.gxlcms.com/1] = '';
    $ubbs['url'][0] = '/\[url\](.*?)\[\/url\]/s';
    $ubbs['url'][https://www.gxlcms.com/1] = '\https://www.gxlcms.com/1';
    $ubbs['url2'][0] = '/\[url=([^\]]+)\](.*?)\[\/url\]/s';
    $ubbs['url2'][https://www.gxlcms.com/1] = '\2';
    $ubbs['email'][0] = '/\[email=([^\]]+)\](.*?)\[\/email\]/s';
    $ubbs['email'][https://www.gxlcms.com/1] = '\2';
    $ubbs['qq'][0] = '/\[qq\]([0-9]{5,https://www.gxlcms.com/10})\[\/qq\]/s';
    $ubbs['qq'][https://www.gxlcms.com/1] = '点击这里给我发消息';
    $ubbs['color'][0] = '/\[color=([^\]]+)\](.*?)\[\/color\]/s';
    $ubbs['color'][https://www.gxlcms.com/1] = '\2';
    $ubbs['font'][0] = '/\[font=([^\]]+)\](.*?)\[\/font\]/s';
    $ubbs['font'][https://www.gxlcms.com/1] = '\2';
    $ubbs['size'][0] = '/\[size=([0-9]+)\](.*?)\[\/size\]/s';
    $ubbs['size'][https://www.gxlcms.com/1] = '\2';
    $ubbs['sizept'][0] = '/\[size=([0-9,pt]+)\](.*?)\[\/size\]/s';
    $ubbs['sizept'][https://www.gxlcms.com/1] = '\2';
    $ubbs['align'][0] = '/\[align=([^\]]+)\](.*?)\[\/align\]/s';
    $ubbs['align'][https://www.gxlcms.com/1] = '\2';
    $ubbs['media'][0] = '/\[media\](.*?)\[\/media\]/s';
    $ubbs['media'][https://www.gxlcms.com/1] = '';
    $ubbs['list'][0] = '/\[list\](.*?)\[\/list\]/s';
    $ubbs['list'][https://www.gxlcms.com/1] = '
      \https://www.gxlcms.com/1
    ';
    $ubbs['list2'][0] = '/\[list=([0-9]+)\](.*?)\[\/list\]/s';
    $ubbs['list2'][https://www.gxlcms.com/1] = '
      \2
    ';
    $ubbs['indent'][0] = '/\[indent\](.*?)\[\/indent\]/s';
    $ubbs['indent'][https://www.gxlcms.com/1] = '\https://www.gxlcms.com/1';
    $ubbs['table'][0] = '/\[table([=,0-9,%]*)\](.*?)\[\/table\]/s';
    $ubbs['table'][https://www.gxlcms.com/1] = '\2';
    $ubbs['tr'][0] = '/\[tr\](.*?)\[\/tr\]/s';
    $ubbs['tr'][https://www.gxlcms.com/1] = '\https://www.gxlcms.com/1';
    $ubbs['td'][0] = '/\[td\](.*?)\[\/td\]/s';
    $ubbs['td'][https://www.gxlcms.com/1] = '
    \https://www.gxlcms.com/1';
    $ubbs['td2'][0] = '/\[td([^(\]|\[)]+)\](.*?)\[\/td\]/s';
    $ubbs['td2'][https://www.gxlcms.com/1] = '
    \2';
    $str = str_replace('[*]','
  • ',$str);
    foreach ($ubbs as $ubb){
    $str = ubb_replace($ubb[0],$ubb[https://www.gxlcms.com/1],$str);
    }
    return $str;
    }
    function ubb_replace($pattern,$replacement,$str){
    do {
    $str_ret = $str;
    $str = preg_replace($pattern,$replacement,$str);
    }while($$str);
    return $str_ret;
    }
    ?>

    编码 modifier.unescape.php
    代码如下:

    function smarty_modifier_unescape($str)
    {
    $str = rawurldecode($str);
    preg_match_all("/(?:%u.{4})|[^%]+/",$str,$r);
    $ar = $r[0];
    foreach($ar as $k=>$v) {
    if(substr($v,0,2) == "%u" && strlen($v) == 6)
    $ar[$k] = iconv("UCS-2","GB2https://www.gxlcms.com/3https://www.gxlcms.com/12",@pack("H4",substr($v,-4)));
    }
    return join("",$ar);
    }

    人气教程排行