phpsmarty函数扩展
扩展 函数 phpSmarty
2023-06-13 09:14:17 时间
中文截取modifier.cn_truncate.php
复制代码代码如下:
functionsmarty_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,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
<?php
functionsmarty_modifier_ubb($str){
$ubbs["quote"][0]="/\[quote\](.*?)\[\/quote\]/s";
$ubbs["quote"][1]="<blockquote>引用:<hrsize=1>\1<hrsize=1></blockquote>";
$ubbs["b"][0]="/\[b\](.*?)\[\/b\]/s";
$ubbs["b"][1]="<b>\1</b>";
$ubbs["i"][0]="/\[i\](.*?)\[\/i\]/s";
$ubbs["i"][1]="<i>\1</i>";
$ubbs["u"][0]="/\[u\](.*?)\[\/u\]/s";
$ubbs["u"][1]="<u>\1</u>";
$ubbs["li"][0]="/\[li\](.*?)\[\/li\]/s";
$ubbs["li"][1]="<li>\1</li>";
$ubbs["img"][0]="/\[img\](.*?)\[\/img\]/s";
$ubbs["img"][1]="<imgborder="0"src="\1">";
$ubbs["img2"][0]="/\[img=([^,]+),([^\]]+)\](.*?)\[\/img\]/s";
$ubbs["img2"][1]="<imgborder="0"width="\1"height="\2"src="\3">";
$ubbs["url"][0]="/\[url\](.*?)\[\/url\]/s";
$ubbs["url"][1]="<ahref="\1"target="_blank">\1</a>";
$ubbs["url2"][0]="/\[url=([^\]]+)\](.*?)\[\/url\]/s";
$ubbs["url2"][1]="<ahref="\1"target="_blank">\2</a>";
$ubbs["email"][0]="/\[email=([^\]]+)\](.*?)\[\/email\]/s";
$ubbs["email"][1]="<ahref="mailto:\2">\2</a>";
$ubbs["qq"][0]="/\[qq\]([0-9]{5,10})\[\/qq\]/s";
$ubbs["qq"][1]="<atarget="new"href="tencent://message/?uin=\1&Site=www.52515.net&Menu=yes"><imgborder="0"src="http://wpa.qq.com/pa?p=1:\1:\1"alt="点击这里给我发消息"></a>";
$ubbs["color"][0]="/\[color=([^\]]+)\](.*?)\[\/color\]/s";
$ubbs["color"][1]="<fontcolor="\1">\2";
$ubbs["font"][0]="/\[font=([^\]]+)\](.*?)\[\/font\]/s";
$ubbs["font"][1]="<fontface="\1">\2";
$ubbs["size"][0]="/\[size=([0-9]+)\](.*?)\[\/size\]/s";
$ubbs["size"][1]="<fontsize="\1" style="line-height:\1em;">\2";
$ubbs["sizept"][0]="/\[size=([0-9,pt]+)\](.*?)\[\/size\]/s";
$ubbs["sizept"][1]="<fontstyle="font-size:\1">\2";
$ubbs["align"][0]="/\[align=([^\]]+)\](.*?)\[\/align\]/s";
$ubbs["align"][1]="<divalign="\1">\2";
$ubbs["media"][0]="/\[media\](.*?)\[\/media\]/s";
$ubbs["media"][1]="<embedsrc="\1"></embed>";
$ubbs["list"][0]="/\[list\](.*?)\[\/list\]/s";
$ubbs["list"][1]="<ul>\1</ul>";
$ubbs["list2"][0]="/\[list=([0-9]+)\](.*?)\[\/list\]/s";
$ubbs["list2"][1]="<ol>\2</ol>";
$ubbs["indent"][0]="/\[indent\](.*?)\[\/indent\]/s";
$ubbs["indent"][1]="<divstyle="text-indent:20px;">\1";
$ubbs["table"][0]="/\[table([=,0-9,%]*)\](.*?)\[\/table\]/s";
$ubbs["table"][1]="<tablestyle="border:#0099FF1pxdotted;border-right-width:0px;border-top-width:0px;">\2";
$ubbs["tr"][0]="/\[tr\](.*?)\[\/tr\]/s";
$ubbs["tr"][1]="<tr>\1";
$ubbs["td"][0]="/\[td\](.*?)\[\/td\]/s";
$ubbs["td"][1]="<tdstyle="border:#0099FF1pxdotted;border-left-width:0px;border-bottom-width:0px;"> \1";
$ubbs["td2"][0]="/\[td([^(\]|\[)]+)\](.*?)\[\/td\]/s";
$ubbs["td2"][1]="<tdstyle="border:#0099FF1pxdotted;border-left-width:0px;border-bottom-width:0px;"> \2";
$str=str_replace("[*]","<li>",$str);
foreach($ubbsas$ubb){
$str=ubb_replace($ubb[0],$ubb[1],$str);
}
return$str;
}
functionubb_replace($pattern,$replacement,$str){
do{
$str_ret=$str;
$str=preg_replace($pattern,$replacement,$str);
}while($$str);
return$str_ret;
}
?>
编码modifier.unescape.php
functionsmarty_modifier_unescape($str)
{
$str=rawurldecode($str);
preg_match_all("/(?:%u.{4})|[^%]+/",$str,$r);
$ar=$r[0];
foreach($aras$k=>$v){
if(substr($v,0,2)=="%u"&&strlen($v)==6)
$ar[$k]=iconv("UCS-2","GB2312",@pack("H4",substr($v,-4)));
}
returnjoin("",$ar);
}
相关文章
- Unity SKFramework框架(十四)、Extension 扩展函数
- 7个有用的Jupyter扩展
- PHP ImageMagick扩展有哪些函数?PHP ImageMagick扩展的使用方法
- 【Kotlin】扩展函数 ( 扩展函数声明 | 调用方式 | 与成员函数优先级 | 接收者空值处理 )
- 【组合数学】生成函数 ( 使用生成函数求解不定方程解个数示例 2 | 扩展到整数解 )
- 【Kotlin】扩展函数 ② ( 扩展属性 | 为可空类型定义扩展函数 | 使用 infix 关键字修饰单个参数扩展函数的简略写法 )
- 【Kotlin】扩展函数总结 ★ ( 超类扩展函数 | 私有扩展函数 | 泛型扩展函数 | 扩展属性 | 定义扩展文件 | infix 关键字用法 | 重命名扩展函数 | 标准库扩展函数 )
- 【Kotlin】DSL 领域特定语言 ( apply 标准库函数分析 | 普通匿名函数 | 扩展匿名函数 | 泛型扩展匿名函数 )
- .NET或将引入类型类和扩展详解编程语言
- MySQL实现水平扩展的技术要点(mysql水平扩展)
- and 扩展Oracle命令的功能:Expanding Oracle Commandability(oracle命令exp)
- 系统Linux分区构建文件系统助你迅速扩展存储空间(linux分区文件)
- MySQL极限:扩展数据库容量(数据库容量mysql)
- Linux逻辑卷管理器(LVM):扩展文件系统的利器(linuxlv)
- 编写自己的php扩展函数
- 让firefox支持IE的一些方法的javascript扩展函数代码
- JavascriptFunction对象扩展之延时执行函数
- jQuery的实现原理的模拟代码-4重要的扩展函数extend
- jQuery下扩展插件和拓展函数的写法(匿名函数使用的典型例子)