Why does the PHP code embedded in HTML be commented out by the browser?

Source: Internet
Author: User

HTML embedded in the PHP code, there is no output content, execution is commented out. What's the reason? I have a local build xamp environment, the file extension from HTML to PHP is not a problem?

For:

PHP can be written in HTML, such as

<body>

<?php echo ' fffffff ';? >

</body>

However, if you insert a PHP statement, you must use the PHP environment to run the HTML file to be effective, such as wampserver.

In addition, the suffix to change the HTML to PHP, because HTML can not parse the content of PHP, unless using the template engine, such as: TP (thinkphp).

When accessing a webpage, the server will determine how to process the page according to the file extension, in general, when checking to the extension of HTM or HTML, the server will directly render the file to the browser side, do not do any processing, if the extension is detected as PHP, shtml, ASP or JSP files, The server first parses the files into HTML code and then renders the code to the process. If you want to be able to run PHP code in an HTML file, you need to modify the Apache configuration file.

First, open the installation directory installed in Apache, which is found under apache\conf: "httpd.conf" file, open with Notepad, and add the following code at the end:

As shown in the following:

Note

(1) After adding the above code, the Apache server must be restarted;

(2) The HTML file must be placed in the Apache configuration file httpd.conf documentroot The specified directory, otherwise it will not run, see

If you only want to include and run PHP scripts in an HTML file, you can set this up:

As shown, where index.html is a file that has been added with PHP code (script), #AddType the # in front of the application/x-httpd-php. htm. html, indicating that the line statement is commented out

Turn from: Mu class quiz Portal

Why does the PHP code embedded in HTML be commented out by the browser?

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.