www.webdeveloper.com
Results 1 to 5 of 5

Thread: filename conventions for HTML fragments

  1. #1
    Join Date
    Aug 2010
    Location
    San Diego
    Posts
    242

    filename conventions for HTML fragments

    I have files with fragments of boilerplate HTML that will be read and output by PHP. I'd rather not use ".html" extension for these files because I'd like to reserve ".html" to indicate a complete HTML page.

    Is there an established filename extension for HTML fragments?

    ...Mike

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    If you are include()-ing it into PHP scripts, you can give it any extension, as PHP won't care. I typically give it a .php suffix so that I can throw a line or two of code at the top to keep it from being called directly via HTTP (if that is a concern).
    PHP Code:
    <?php
    if(realpath($_SERVER['SCRIPT_FILENAME']) == realpath(__FILE__)) {
       
    header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
       exit;
    }
    ?>
    <p>Your stuff goes here...</p>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2010
    Location
    San Diego
    Posts
    242
    Sorry I wasn't clear. I'm thinking of something like this:

    PHP Code:
    echo '<p class="contact-info">';
    readfile ("contact-info.htxt");
    echo 
    '</p>'
    contact-info.htxt would contain

    1234 5th St.<br />
    Los Angeles, CA 91234<br />
    ph. (310) 555-1234<br />
    fax (310) 555-6789<br />
    So I'm using extension .htxt to indicate text with html markup, but not a complete well-formed html page. I wondered if there was already an extension established for this purpose.

    Thanks,
    ...Mike

  4. #4
    Join Date
    Oct 2007
    Posts
    370
    I don't think there is one, but maybe you just established it.

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    readfile(), include(), require(), file_get_contents(): it doesn't matter. PHP won't care what the suffix is, so use whatever you like -- including my suggestion for ".php" if you want to prevent direct access via browsers.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles