Page 1 of 1

php files ?

Posted: Fri May 07, 2010 5:06 pm
by kareem100
Hi,

I'm learning PHP at a local college.

I've wriiten some files which have a .html.php extension. I'm a little bit confused, are these php files or are they html files. or are they both?

Regards,
Kareem.

Re: php files ?

Posted: Fri May 07, 2010 5:34 pm
by John Cartwright
Filenames may contain multiple periods as a means to organize files by their functionality, but it is the last one that determines the extension.

index.foo.bar.php

Re: php files ?

Posted: Fri May 07, 2010 8:04 pm
by califdon
A plain HTML file, without any PHP in it, usually is given a file extension of .htm or .html. By default, the file extension .php is given a file that contains any PHP code. This is so the web server can determine whether or not a file needs to be preprocessed by the PHP parser before sending the document to the browser. It is possible to configure the web server to send other extensions to the parser, but ordinarily the dafault is accepted. It would be unusual for a file to be given a combination, such as your post showed.

Re: php files ?

Posted: Sat May 08, 2010 5:07 pm
by kareem100
Hi,

Yes I understand that.

Am I right in saying that a pure HTML file can have any extension ( or no extension at all ) and would still work.

Regards,

Kareem

Re: php files ?

Posted: Sat May 08, 2010 5:36 pm
by califdon
Not really. A web server sends a header that defines what kind of a file it is sending (a web page, a multimedia file, a file to be downloaded, etc.) and if it doesn't recognize the kind of file it is asked to send, it cannot create the appropriate header. Generally, web pages (that is, HTML protocol) are given extensions of .htm or .html. It would be possible to configure a server otherwise, but there's little reason to ever do so.

Re: php files ?

Posted: Sun May 09, 2010 4:07 pm
by kareem100
Hi,

So if a file contained php code and html code, what extension would the file have. would it be .php or .html

Re: php files ?

Posted: Sun May 09, 2010 6:23 pm
by califdon
kareem100 wrote:Hi,

So if a file contained php code and html code, what extension would the file have. would it be .php or .html
Go back and read the second sentence of my first reply.