Home >Backend Development >PHP Tutorial >Example analysis of smart variable modification usage in php_PHP tutorial

Example analysis of smart variable modification usage in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:51:01777browse

Example analysis of smart variable modification usage in php

test.php code:

1

2

3

4

5

6

7

8

9

require 'libs/Smarty.class.php'; //包含Smarty类库文件

$smarty = new Smarty; //创建一个新的Smarty对象

$total = 12345; //对$total赋值

$smarty->assign("total",$total); //对模版中的变量赋值

$formatted_total = number_format($total); //格式化$total

$smarty->assign("formatted_total",$formatted_total); //对模版中的变量赋值

$smarty->display('test1.htm'); //显示页面

?>

1 2

3

4

5

1

2

3

4

5

6

7

8

9

Smarty Test

Total is {$total}

Formatted Total is {$formatted_total}

6 7

8

9

1

2

3

4

5

6

7

8

9

10

11

12

13

compiled from test1.htm */ ?>

Smarty Test

Total is _tpl_vars['total']; ?>

Formatted Total is _tpl_vars['formatted_total']; ?>

$smarty = new Smarty; //Create a new Smarty object

$total = 12345; //Assign value to $total

1

2

3

4

5

6

7

8

9

Smarty Test

Total is {$total}

Formatted Total is {$total|number_format}

$smarty->assign("total",$total); //Assign values ​​to variables in the template $formatted_total = number_format($total); //Format $total $smarty->assign("formatted_total",$formatted_total); //Assign values ​​to variables in the template $smarty->display('test1.htm'); //Display page ?>
test1.html template code:
1 2 3 4 5 6 7 8 9 Smarty Test

Total is {$total}

Formatted Total is {$formatted_total}

Compiled test.html.php code:
1 2 3 4 5 6 7 8 9 10 11 12 13 <🎜>compiled from test1.htm */ ?> Smarty Test

Total is _tpl_vars['total']; ?>

Formatted Total is _tpl_vars['formatted_total']; ?>

The test1.html template can be rewritten as test2.html like this:
1 2 3 4 5 6 7 8 9 Smarty Test

Total is {$total}

Formatted Total is {$total|number_format}

Then the corresponding test.php code is changed to:

1

2

3

4

5

6

7

require 'libs/Smarty.class.php'; //包含Smarty类库文件

$smarty = new Smarty; //创建一个新的Smarty对象

$total = 12345;

$smarty->assign("total",$total); //对模版中的变量赋值

$smarty->display('test2.htm'); //显示页面

?>

1 2

3

4

5

6 7

?>
Browser display: Total is 12345 Formatted Total is 12,345 I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/1015339.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1015339.htmlTechArticleExample analysis of smart variable modification usage in php test.php code: 1 2 3 4 5 6 7 8 9 ?php require 'libs/Smarty.class.php'; //Include Smarty class library file $smarty = new Smarty; //Create a new...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn