搜尋
首頁php教程php手册php smarty函数扩展

php smarty函数扩展

Jun 13, 2016 pm 12:17 PM
phpsmarty中文程式碼函數複製截取擴充

中文截取 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) return $string;
}
$str = strip_tags($string);
$j = 0;
for($i=0;$iif(ord(substr($str,$i,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) 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'][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] = '
  • \1
  • ';
    $ubbs['img'][0] = '/\[img\](.*?)\[\/img\]/s';
    $ubbs['img'][1] = 'php smarty函数扩展';
    $ubbs['img2'][0] = '/\[img=([^,]+),([^\]]+)\](.*?)\[\/img\]/s';
    $ubbs['img2'][1] = 'php smarty函数扩展';
    $ubbs['url'][0] = '/\[url\](.*?)\[\/url\]/s';
    $ubbs['url'][1] = '\1';
    $ubbs['url2'][0] = '/\[url=([^\]]+)\](.*?)\[\/url\]/s';
    $ubbs['url2'][1] = '\2';
    $ubbs['email'][0] = '/\[email=([^\]]+)\](.*?)\[\/email\]/s';
    $ubbs['email'][1] = '\2';
    $ubbs['qq'][0] = '/\[qq\]([0-9]{5,10})\[\/qq\]/s';
    $ubbs['qq'][1] = '点击这里给我发消息';
    $ubbs['color'][0] = '/\[color=([^\]]+)\](.*?)\[\/color\]/s';
    $ubbs['color'][1] = '\2';
    $ubbs['font'][0] = '/\[font=([^\]]+)\](.*?)\[\/font\]/s';
    $ubbs['font'][1] = '\2';
    $ubbs['size'][0] = '/\[size=([0-9]+)\](.*?)\[\/size\]/s';
    $ubbs['size'][1] = '\2';
    $ubbs['sizept'][0] = '/\[size=([0-9,pt]+)\](.*?)\[\/size\]/s';
    $ubbs['sizept'][1] = '\2';
    $ubbs['align'][0] = '/\[align=([^\]]+)\](.*?)\[\/align\]/s';
    $ubbs['align'][1] = '
    \2';
    $ubbs['media'][0] = '/\[media\](.*?)\[\/media\]/s';
    $ubbs['media'][1] = '';
    $ubbs['list'][0] = '/\[list\](.*?)\[\/list\]/s';
    $ubbs['list'][1] = '
      \1
    ';
    $ubbs['list2'][0] = '/\[list=([0-9]+)\](.*?)\[\/list\]/s';
    $ubbs['list2'][1] = '
      \2
    ';
    $ubbs['indent'][0] = '/\[indent\](.*?)\[\/indent\]/s';
    $ubbs['indent'][1] = '
    \1';
    $ubbs['table'][0] = '/\[table([=,0-9,%]*)\](.*?)\[\/table\]/s';
    $ubbs['table'][1] = '\2';
    $ubbs['tr'][0] = '/\[tr\](.*?)\[\/tr\]/s';
    $ubbs['tr'][1] = '\1';
    $ubbs['td'][0] = '/\[td\](.*?)\[\/td\]/s';
    $ubbs['td'][1] = '
     \1';
    $ubbs['td2'][0] = '/\[td([^(\]|\[)]+)\](.*?)\[\/td\]/s';
    $ubbs['td2'][1] = '
     \2';
    $str = str_replace('[*]','
  • ',$str);
    foreach ($ubbs as $ubb){
    $str = ubb_replace($ubb[0],$ubb[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","GB2312",@pack("H4",substr($v,-4)));
    }
    return join("",$ar);
    }

  • 陳述
    本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

    熱AI工具

    Undresser.AI Undress

    Undresser.AI Undress

    人工智慧驅動的應用程序,用於創建逼真的裸體照片

    AI Clothes Remover

    AI Clothes Remover

    用於從照片中去除衣服的線上人工智慧工具。

    Undress AI Tool

    Undress AI Tool

    免費脫衣圖片

    Clothoff.io

    Clothoff.io

    AI脫衣器

    Video Face Swap

    Video Face Swap

    使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

    熱門文章

    熱工具

    SublimeText3漢化版

    SublimeText3漢化版

    中文版,非常好用

    記事本++7.3.1

    記事本++7.3.1

    好用且免費的程式碼編輯器

    SublimeText3 Linux新版

    SublimeText3 Linux新版

    SublimeText3 Linux最新版

    MantisBT

    MantisBT

    Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

    SAP NetWeaver Server Adapter for Eclipse

    SAP NetWeaver Server Adapter for Eclipse

    將Eclipse與SAP NetWeaver應用伺服器整合。