How to modify the smarty variable in php-example analysis-PHP Tutorial

Source: Internet
Author: User
Analysis of the smarty variable modifier usage instance in php. Test. php code: 123456789? PhprequirelibsSmarty. class. php; contains the Smarty class library file $ smartynewSmarty; creates a new php smarty variable modifier usage instance for analysis

Test. php code:

1

2

3

4

5

6

7

8

9

Require 'libs/Smarty. class. php'; // contains the Smarty class library file

$ Smarty = new Smarty; // create a new Smarty object

$ Total = 12345; // assign a value to $ total

$ 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

?>

Code of the test1.html template:

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:

1

2

3

4

5

6

7

8

9

Smarty Test

Total is {$ total}

Formatted Total is {$ total | number_format}

The corresponding test. php code is changed:

1

2

3

4

5

6

7

Require 'libs/Smarty. class. php'; // contains the Smarty class library file

$ Smarty = new Smarty; // create a new Smarty object

$ Total = 12345;

$ Smarty-> assign ("total", $ total); // assign values to variables in the template

$ Smarty-> display('test2.htm'); // Display Page

?>

Browser display:

Total is 12345
Formatted Total is 12,345

I hope this article will help you with php programming.

Example test. php code: 1 2 3 4 5 6 7 8 9? Php require 'libs/Smarty. class. php'; // contains the Smarty class library file $ smarty = new Smarty; // create a new...

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.