php smarty函数扩展

2019-04-09 23:00:28丽君

$ubbs['media'][0] = '/[media](.*?)[/media]/s';
$ubbs['media'][1] = '<embed src="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] = '<div style="text-indent: 20px;">1';
$ubbs['table'][0] = '/[table([=,0-9,%]*)](.*?)[/table]/s';
$ubbs['table'][1] = '<table style="border:#0099FF 1px dotted;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] = '<td style="border:#0099FF 1px dotted; border-left-width:0px; border-bottom-width:0px;"> 1';
$ubbs['td2'][0] = '/[td([^(]|[)]+)](.*?)[/td]/s';
$ubbs['td2'][1] = '<td style="border:#0099FF 1px dotted; border-left-width:0px; border-bottom-width:0px;"> 2';
$str = str_replace('[*]','<li>',$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);
}
相关文章 大家在看