PHP explanatory template Phplib_PHP tutorial in improved Template

Source: Internet
Author: User
Improved PHP explanatory template Phplib. Before explaining the use of PHP explanatory template Phplib, explain why the template system using php labels should continue to improve. In fact, this is mainly because the PHP tag is for the artist

Before explaining the use of PHP explanatory template Phplib, explain why the template system using php labels should continue to improve. In fact, this is mainly because the PHP tag is inconvenient for the artist. They prefer to directly use such visualized labels, such as {title }.

First, we will modify the previous example to use visualized labels for processing. Step 1: Change shownews. php to shownews. tpl, and change the php tag to a visualized tag. the shownews. tpl code is as follows:

  1. < Html>
  2. < Head>
  3. < Title>Display News</Title>
  4. </Head>
  5. < Body>
  6. {Title}
  7. </Body>
  8. </Html>

Step 2: how to implement the effect of listnews. php? In fact, it is very simple. I just need to replace {title} with another one? Therefore, the modified listnews. php code is as follows:

 
 
  1. <?
  2. Include ('getnews. php ');
  3. // Obtain data
  4. Echo str_replace ('{title }',
  5. $ News, file_get_contents
    ('Shownews. tpl '))
  6. ?>

In fact, the principle of PHP explanatory template Phplib is exactly like this! For example, if we want to use phplib to implement the above functions, we only need to modify the code after listnews. php. is modified as follows:

 
 
  1. <?
  2. Include ('getnews. php ');
  3. // Obtain data
  4. Include ('Template. class. php ');
  5. $ T = new Template ();
  6. $ T-> set_file ('shownesw,
    'Shownews. tpl ');
  7. $ T-> set_var ('news', $ news );
  8. $ T-> parse ('out', 'shownesw ');
  9. $ T-> p ('out ');
  10. ?>

In addition, you can refer to the relevant Manual for the PHP explanatory template Phplib region.


Bytes. In fact, this is mainly because the PHP tag is for the artist...

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.