views:

107

answers:

2

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)

+6  A: 

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.

Pekka
wicked. thanks.
tom
@tom I have one of my webservers set to send `.scary` to the php processor too. You can set it up how you want, the defaults exist for the reasons pekka said though.
+6  A: 

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...
Álvaro G. Vicario
Stack Overflow should warn you when the user has accepted an answer on the question you're typing. It feels like a waste of time.
Álvaro G. Vicario
It's still a fine answer with advanced points and background.
Pekka
@Alvaro, cheer up, you got 5 up votes out of it.
Mark Tomlin