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:
- < Html>
- < Head>
- < Title>Display News</Title>
- </Head>
- < Body>
- {Title}
- </Body>
- </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:
- <?
- Include ('getnews. php ');
- // Obtain data
- Echo str_replace ('{title }',
- $ News, file_get_contents
('Shownews. tpl '))
- ?>
-
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:
- <?
- Include ('getnews. php ');
- // Obtain data
- Include ('Template. class. php ');
- $ T = new Template ();
- $ T-> set_file ('shownesw,
'Shownews. tpl ');
- $ T-> set_var ('news', $ news );
- $ T-> parse ('out', 'shownesw ');
- $ T-> p ('out ');
- ?>
-
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...