-3

I'm currently making a web page which is mostly standard html/css however I have decided I want to include a few bits of PHP in it.

I notice around the web that you rarely see websites that are .php, most websites are .html/htm.

What I'm wondering is...is there any significance to having your file saved as .php or .html when it contains both? It seems to me that it is just as possible to have almost entirely pure html in a html file or a php file and likewise it is perfectly possible to have mostly php in an html file.

Are there any advantages/disadvantages from having a matching file name to the majority content?

Lee Jackson
  • 209
  • 1
  • 2
  • 10
  • how come one sees so few php files around the internet then if you totally need php to run php? – Lee Jackson Jun 01 '13 at 05:29
  • 2
    A PHP file on the server will (probably) have the .php extension, but you can configure the webserver (eg Apache) to hide it - see http://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess – John Carter Jun 01 '13 at 05:32
  • ahhhh, so its just a case of a lot of html being basic sites and so not bothering to hide whilst php sites being more advanced do this. Ta. Jack- like you were never new to php. – Lee Jackson Jun 01 '13 at 05:55
  • `.html` files can run as PHP, just as long as this is added to the `.htaccess` file. => `AddType application/x-httpd-php .html` – Funk Forty Niner Jun 01 '13 at 12:53

5 Answers5

1

Php code will not be evaluated in an html file! That is, unless you specifically set up config in php.ini.

Ziarno
  • 7,366
  • 5
  • 34
  • 40
1

is there any significance to having your file saved as .php or .html when it contains both?

Yes. Webservers essentially run the files with .php extensions and serve the output of those scripts, which is commonly HTML. HTML files are static and are just served the way they're written.

Are there any advantages/disadvantages from having a matching file name to the majority content?

It's not really the "majority" or the "minority". If the file contains PHP code, it is a PHP file and should be saved with a .php extension. If it's just an HTML file, save it as a .html file.

Blender
  • 289,723
  • 53
  • 439
  • 496
1

The only downside I can see is it doesn't save well from the browser (most end users won't have an application associated with the .php extension).

Anyway a little rewrite magic and index.php == index.html

Orangepill
  • 24,500
  • 3
  • 42
  • 63
1

There is no difference with modern implementations of PHP. There was a time where implementations of web servers relied on naming conventions solely to determine what parser to use for that particular file. Now web servers like Apache allow any file to be run through PHP by setting simple configuration options. Typically, it is good practice to keep URLs consistent across all pages within a site so that it is more intuitive to browse. For instance, if I'm at a site that has the following URIs:

  • /products/super-awesome-shirt/large.html
  • /products/super-awesome-shirt/small.html

I would assume that I can point my browser to /products/super-awesome-shirt/medium.html and up would pop a page showing a medium sized super awesome shirt. Whereas, if it were /products/super-awesome-shirt/medium.php, it would be confusing for me (I wouldn't easily guess this page has a different extension) because other pages have .html endings.

There are tons of easy ways to make all of your urls tidy and intuitive in Apache using mod_rewrite. The same thing applies to IIS with respect to URL rewriting, but it's been years since I've had to configure them. I'm sure it's something a little bit of googling would find.

Doc
  • 11
  • 2
0

1).html is generally use just for html with no serverside code.

2).php is used for serverside php code and html if required.

3)They can be used for anything, it just depends on the setup.

See this DIFF

GautamD31
  • 28,552
  • 10
  • 64
  • 85