Test Test

Home  >  Article  >  Backend Development  >  PHP code Why embedding PHP code in HTML files has no effect

PHP code Why embedding PHP code in HTML files has no effect

WBOY
WBOYOriginal
2016-07-29 08:33:111266browse

Due to self-study, I don’t know or understand a lot of common sense...

Question:

If the suffix of .html is not displayed in php printing, change the suffix to .php and it will return to normal (prerequisite: server Set up)

<code><span><!DOCTYPE html></span><span><<span>html</span><span>lang</span>=<span>"en"</span>></span><span><<span>head</span>></span><span><<span>meta</span><span>charset</span>=<span>"utf-8"</span>></span><span><<span>title</span>></span>测试<span></<span>title</span>></span><span></<span>head</span>></span><span><<span>body</span>></span><span><<span>h1</span>></span>hello<span></<span>h1</span>></span><span><span><?php</span><span>$a</span>=<span>array</span>(<span>"Dog"</span>,<span>"Cat"</span>,<span>"Horse"</span>);
            print_r(<span>$a</span>);
        <span>?></span></span><span></<span>body</span>></span><span></<span>html</span>></span></code>

Reason:

Static web pages mainly include html, CSS, and JavaScript
Dynamic web page technologies mainly include JSP, Asp.net, PHP, etc. Web pages are divided into two types: static and dynamic. The content of the static page is unchanged, and the extension is usually html. If your browser requests this, the server will directly pass it to you; the content of the dynamic page changes according to conditions, and everyone may see it differently. The code in the dynamic page is processed by the server before being passed to the browser.

So how does the server know whether this file should be processed before transmitting it? The simplest way is to use the extension to distinguish it. When the server encounters the .php suffix, it will process it first and then send it to the browser. PHP pages can also include HTML page content. If they are all HTML content, it is equivalent to the PHP processor opening the file and looking at it. If there is nothing to process, it will be directly thrown to the browser. The effect seen by the browser is the same, but the server There is actually a processing process.

If the machine does not have a running environment, the php file cannot be run. If you directly use IE to view it, you will be prompted for downloading or other problems. If you want to use IE to view it, then change the extension to .html or .htm and click directly to open it, but the PHP code will not be displayed.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i

').text(i)); }; $numbering.fadeIn(1700); }); }); The above introduces the PHP code. Why embedding the PHP code in the HTML file has no effect, including the content of the PHP code. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn