How can we better distinguish php files from HTML code?

Source: Internet
Author: User
As we all know, php is a script programming language embedded with html on the server. however, if you use the embedded html method to build a website, the code will soon become ambitious and uncontrollable. how can we separate php code with html to make a lib (Template) similar to dw?

As we all know, php is a script programming language embedded with html on the server. however, if you use the embedded html method to build a website, the code will soon become ambitious and uncontrollable. how can we separate php code from html to make a lib (Template) similar to dw, so that the page is more easily corrected and the code is easily protected?

Later, I read a lot of articles, saying that phplib can be implemented. after reading a few pages, I felt dizzy and lost my hope, thank you for your consideration !). However, the title still has to be resolved. after being bored for many days, I had an occasional opportunity to download the source code of the vbb Forum. after reading it roughly, I found that I rarely saw the html code except the php file. I wonder if this is the style I want. still dizzy: (the only thing I learned is that it puts the html code in the database and calls it through the php file. after a series of processing, use the eval function to bring the expected variables into the dynamic pages that are naturally required. in this way, I have not looked at the vbb source code, but switched to the eval function. the php Chinese manual first introduces eval functions:

Function: eval ()

Miscellaneous Library

Eval

Returns the value to the string.

Syntax: void eval (string code_str );

Return value: None

Correspondence type: Material Processing

Content clarification

This function can be used to generate variable values in the string, which is usually used to process the material of the material. Parameter code_str
Is the string to be processed. It is worth noting that the string to be processed must conform to the PHP string pattern and end
There must be a semicolon. The strings processed by this function will be continued to the end of the PHP program.

Application model

$ String = 'cup ';
$ Name = 'coffee ';
$ Str = '$ string contains $ name.
';
Echo $ str;
Eval ('\ $ str = \' $ str \';');
Echo $ str;
?>

In this example, the return value is

$ Name is included in $ string.
The cup contains coffee.


The example test has no title. However, when I test the following code, an error is displayed:

$ Aa = 'My name is yyy! ';
$ Str ='';
Eval ('\ $ str = \' $ str \';');
Echo $ str;
?>
After thinking twice, I asked for help. in a series of solutions proposed by netizens, I finally succeeded in this method:

$ Aa = 'My name is yyy! ';
$ Str ='';
Eval ('\ $ str = \' $ str \';');
Echo $ str;
?>

However, when I inserted $ str into the following table and then extracted it, it went wrong again, so it was annoying.
Died.

Database evaltest

# 'Enabtest' table structure'

Create table envtest (
Id tinyint (4) not null auto_increment,
Sour mediumtext,
Primary key (id ),
UNIQUE id (id ),
KEY id_2 (id)
);

# 'Enabtest'

Insert into envtest VALUES ('1 ','');

The PHP file is as follows:

$ Aa = 'My name is yyy! ';
$ Conn = mysql_connect ('localhost', 'root ','');

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.