I read hundreds of PHP examples and seen many php vids but I never really heard a reason why a file needs the .php extension.

In my trial and error learning it seems like a .html can handle a little php code but if you use alot you need a .php extension.

Like this example of mine....

100 lines of html
then
50 lines of php
then
100 lines of html

This example didn't work when it had a .html extension but when I switched to .php it worked.

I was just curious if there is definition of why and when you use a .php extension?

    ok..

    if you have <?php ?> in your code the file must be .php unless your webserver is setup different.

      I read hundreds of PHP examples and seen many php vids but I never really heard a reason why a file needs the .php extension.
      ...
      I was just curious if there is definition of why and when you use a .php extension?

      From what I understand, the web server interprets the content of files served depending on their MIME type. Aside from MIME headers, it may use the file extension to determine the MIME type.

      Consequently, the web server does not have to serve .php files as PHP scripts, or serve PHP scripts with a .php extension. You could use any file extension, including .html. It all depends on how you configure the web server.

      In my trial and error learning it seems like a .html can handle a little php code but if you use alot you need a .php extension.

      It follows that that is not true. If the web server has been configured to serve .html files as PHP scripts, the file will be served as a PHP script, regardless of how much PHP code it has as content.

        Write a Reply...