开发者

If you can embedd php into a .html file, why would you use .php?

Is there a reason why certain pages are made as 开发者_开发知识库.php when you can put php into a .html file? Is it simply for the sake of organizing your files? Or does it affect how the page loads?

(I'm talking about the file extension)


Whether files with the extension .html are parsed as PHP is down to the server's configuration. Usually, they're not.

That is for a reason: When set that way, the PHP interpreter has to look over every HTML file that gets served, even if it doesn't contain any PHP code at all. That's not good for performance.


File extensions are merely a convention. You can save a JPEG picture with .html extension and configure things to get it properly loaded. And, of course, being a convention, there's nothing magical in them: renaming foo.mpg to foo.avi won't convert your movie to DivX. The Unix operating system doesn't even use extensions to identify programs.

But, of course, they're a very useful convention. If your text editor opens a .php file, it doesn't need to guess what syntax highlighter to apply. If the web server serves a .php files, you don't have to instruct it to handle it to the PHP interpreter.

Some more remarks:

  • There're many server-side languages; PHP is not the only one.
  • The PHP interpreter does not care about the file extension.
  • URLs reflect the file they load almost as many times as they don't.
  • PHP can generate HTML... and GIF pictures, an PDF documents, and MP3 recordings...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜