SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    When to use .XHTML versus .PHP ???

    Is there a fast-and-steady rule of which file extension (i.e. ".xhtml" or ".php") to use on a web page??

    Obviously is all the code is XHTML then you use ".xhtml"

    And if the code is all PHP, you use ".php"

    But what if I have a Registration Form where 80-90% of the code is XHTML with just a little PHP sprinkled in??

    (In therory, you could name any web page with some XHTML as ".xhtml" as long as you made sure to encapsulate your PHP as <?php .... ?> right?!)

    Thanks,


    Amy

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Wrong.

    If you have any PHP code that needs processing then the file extension MUST be .php

    (Unless the server has been set to map the .xhtml file extension to the PHP parser - which would be unusual).
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2009
    Location
    Bavaria, Germany
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you can use another extension, but as siteguru says you have to tell your server that it has to parse it like PHP (perfomance will not boost ). I think the other way around is better: name it .php and let i.e. Apache do the job to rewrite the URLs if you want to have another extension shown to your visitors.

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I have actually never, ever seen a file saved with ".xhtml" as the extension. ".html" and ".htm" are common, but not ".xhtml".

  5. #5
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    I have actually never, ever seen a file saved with ".xhtml" as the extension. ".html" and ".htm" are common, but not ".xhtml".
    This. I hear of *.xhtml extension for the first time.

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Come on guys, the both know fine well what Amy meant.

    Personally, whilst not a complete REST advocate, I think the URI should represent the content being served.

    So .html for me, regardless of the server language being used.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Amy, the simplest way to go about it is to side with the others above... If it uses a server-side language, then use the appropriate server-side extension (so for PHP you would use .php) the reason for this is because even the .php extension can read and parse (x)HTML (it will recognise both the HTML and the PHP code) where as if you provide .htm / .html or .xhtml (yes I have seen this used) it won't recognise anything apart from the HTML

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If you are using HTML and XHTML on your site then .xhtml is the obvious extension to use for the XHTML pages (you just need to make sure you add the appropriate line to your .htaccess file so it gets parsed correctly as XHTML instead of HTML).

    You can use whatever extension you like for whatever you want as long as you set it up to parse correctly. All my .html pages contain PHP while my .htm pages only contain SSI.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •