php files ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kareem100
Forum Newbie
Posts: 11
Joined: Sat May 01, 2010 5:39 pm

php files ?

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: php files ?

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php files ?

Post 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.
kareem100
Forum Newbie
Posts: 11
Joined: Sat May 01, 2010 5:39 pm

Re: php files ?

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php files ?

Post 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.
kareem100
Forum Newbie
Posts: 11
Joined: Sat May 01, 2010 5:39 pm

Re: php files ?

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php files ?

Post 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.
Post Reply