Phpsmarty Function Extension _ php template _ script house

Source: Internet
Author: User
Tags php template
Extension functions are stored in the * Smartylibsplugins directory. The file name format is modifier. xxxx. php, and the function name format is functionsmarty_modifier_xxxx.

Extension functions are stored in the */Smarty/libs/plugins directory. The file name format is modifier. xxxx. php, and the function name format is function smarty_modifier_xxxx.

Chinese: modifier.cn _ truncate. php
The 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
The Code is as follows:
Function smarty_modifier_ubb ($ str ){
$ Ubbs ['quote'] [0] = '/\ [quote \] (. *?) \ [\/Quote \]/s ';
$ Ubbs ['quote'] [1] ='
Reference: \ 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 ['lil'] [0] = '/\ [li \] (. *?) \ [\/Li \]/s ';
$ Ubbs ['lil'] [1] ='
  • \ 1
  • ';
    $ 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] = '\ 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;
    }
    ?>

    Code: modifier. unescape. php
    The 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 );
    }
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.