As we all know, php is a server-side embedded html-based scripting language. However, for a website based on embedded html, the code will soon become huge and uncontrollable. How can we separate php code from html and make a lib (Template) similar to dw so that the page can be modified more easily and the code can be easily maintained?
Later, I read a lot of articles, saying that phplib can be implemented. After reading a few pages, I felt dizzy and lost my desire to read it. However, the problem still has to be solved. By chance, we were able to download the source code of the vbb Forum. After a rough look, we found that, except for the PHP file, we seldom saw the html code. I thought this was not the style I wanted. The only difference was that I knew that it put the html code in the database and called it through the php file. After a series of processing, use the eval function to bring the expected variables into the dynamic pages required for generation. In this way, I did not look at the vbb source code and transferred it to the eval function. The php Chinese manual introduces eval functions as follows:
Function: eval ()
Miscellaneous Library
Eval
Enter the value in the string.
Syntax: void eval (string code_str );
Return value: None
Correspondence type: data processing
Description
This function can be used to substitute variable values in a string for processing data in a database. The code_str parameter is the string to be processed. It is worth noting that the string to be processed must conform to the PHP string format and contain a semicolon at the end. The strings processed by using this function will be continued to the end of the PHP program.
Example
Reference content is as follows:
<? Php
$ String = 'cup ';
$ Name = 'coffee ';
$ Str = '$ name is included in $ string. <br> ';
Echo $ str;
Eval ("$ str =" $ str ";");
Echo $ str;
?>
In this example, the return value is
$ Name is installed in $ string.
The cup contains coffee.
The example test has no problems. However, when I test the following code, an error occurs:
Reference content is as follows:
<?
$ Aa = 'My name is yyy! ';
$ Str = '<input type = "text" name = "textfield" value = "$ aa"> ';
Eval ("$ str =" $ str ";");
Echo $ str;
?>
After thinking about it, I asked for help. In a series of solutions proposed by netizens, I finally ran successfully in this way: