- /**
- * Use php functions in the smarty template engine
- * By bbs.it-home.org
- */
- Require 'libs/Smarty. class. php ';
- $ Smarty = new Smarty;
- $ Smarty-> compile_check = true;
- $ Smarty-> debugging = true;
- $ Str1 = 'testtesttesttest ';
- $ Str2 = 'This is ';
- $ Str3 = 'script school bbs.it-home.org ';
- $ Str4 = 'This is four ';
- $ Smarty-> assign ('str1', $ str1 );
- $ Smarty-> assign ('str2', $ str2 );
- $ Smarty-> assign ('str3', $ str3 );
- $ Smarty-> assign ('str4', $ str4 );
- $ Smarty-> display ('testtest. tpl ');
- ?>
{$ Str1 | strlen}
{$ Str2 | strpos: 'Is '}
{'Utf-8' | iconv: 'gb2312 ': $ str3}
{$ Str4 | str_pad: 20: "-=": STR_PAD_LEFT}
Output result: 162 Test:-= this is four Note: four variables are used to process 1, 2, 3, and 3 parameters that are not allowed. here we record that when the template calls the variables, only one parameter is, directly {$ str1 | function name}. when a function has two parameters, {first parameter | function name: Second parameter}. when there are three parameters, {first parameter | function name: Second parameter: third parameter}. when there are 4, 5, and parameters, and so on ,,,,,,,,,,,, This is used during programming:
- {$ Name | str_ireplace: "$ name": $ arr
If you are interested, you can think about it. |