Questions about calling php built-in functions in smarty
- Function SmartyLen ($ params ){
- Extract ($ params );
- $ Len = strlen ($ text );
- $ Max = $ length;
- For ($ I = 0; $ I <$ length; $ I ++ ){
- $ Chr = substr ($ text, $ I, 1 );
- If (ord ($ chr)> 0x80) // The character is Chinese
- {
- $ Length ++;
- $ I ++;
- $ Len --;
- }
- }
- $ Str = substr ($ text, 0, $ length );
- If ($ len> $ max) $ str. = "...";
- Return $ str;
- }
-
Register a function$ Smarty-> register_function ('len', "SmartyLen ");Template call{Len text = "test" length = "1"} // note that the text and length here are actually the parameters of the two parameter functions in the function, which must be named by the internal variable name of the function. consistent, actually, it is an array. in the function, use extract ($ params); to import the variables in the array to the current symbol table. |