Chinese: modifier.cn _ truncate. php
Copy codeThe Code is as follows:
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, 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
Copy codeThe Code is as follows:
<? Php
Function smarty_modifier_ubb ($ str ){
$ Ubbs ['quote'] [0] = '/\ [quote \] (. *?) \ [\/Quote \]/s ';
$ Ubbs ['quote'] [1] = '<blockquote> reference: $ 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 ['lil'] [0] = '/\ [li \] (. *?) \ [\/Li \]/s ';
$ Ubbs ['lil'] [1] = '<li> \ 1 </li> ';
$ 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] = '<a href = "\ 1" target = "_ blank"> \ 1 </a> ';
$ Ubbs ['url2 '] [0] ='/\ [url = ([^ \] +) \] (. *?) \ [\/Url \]/s ';
$ Ubbs ['url2 '] [1] =' <a href = "\ 1" target = "_ blank"> \ 2 </a> ';
$ Ubbs ['email '] [0] ='/\ [email = ([^ \] +) \] (. *?) \ [\/Email \]/s ';
$ Ubbs ['email '] [1] =' <a href = "mailto: \ 2"> \ 2 </a> ';
$ Ubbs ['qq'] [0] = '/\ [qq \] ([0-9] {5, 10}) \ [\/qq \]/s ';
$ Ubbs ['qq'] [1] = '<a target = "new" href = "tencent: // message /? Uin = \ 1 & Site = www.52515.net & Menu = yes "> </a> ';
$ Ubbs ['color'] [0] = '/\ [color = ([^ \] +) \] (. *?) \ [\/Color \]/s ';
$ Ubbs ['color'] [1] = '<font color = "\ 1"> \ 2 ';
$ Ubbs ['font'] [0] = '/\ [font = ([^ \] +) \] (. *?) \ [\/Font \]/s ';
$ Ubbs ['font'] [1] = '<font face = "\ 1"> \ 2 ';
$ Ubbs ['SIZE'] [0] = '/\ [size = ([0-9] +) \] (. *?) \ [\/Size \]/s ';
$ Ubbs ['SIZE'] [1] = '<font size = "\ 1" style = "line-height: \ 1em;"> \ 2 ';
$ Ubbs ['sizept '] [0] ='/\ [size = ([0-9, pt] +) \] (. *?) \ [\/Size \]/s ';
$ Ubbs ['sizept '] [1] =' <font style = "font-size: \ 1"> \ 2 ';
$ Ubbs ['align '] [0] ='/\ [align = ([^ \] +) \] (. *?) \ [\/Align \]/s ';
$ Ubbs ['align '] [1] =' <div align = "\ 1"> \ 2 ';
$ 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;
}
?>
Code: modifier. unescape. php
Copy codeThe Code is as follows:
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 );
}