SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Jul 2012
    Location
    Ontario, Canada
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can html or php, but not php within html

    Greetings, and thanx in advance for all time & effort.



    Installed & using "xampp"

    Using Kevin Yank's "PHP & MySQL: Novice to Ninja"
    <!DOCTYPE html>
    <html lang="en">
    **<head>
    ** *<meta charset="utf-8">
    ** *<title>Today&rsquo;s Date</title>
    **</head>
    **<body>
    ** *<p>Today&rsquo;s date (according to this web server) is
    ** * *<?php
    ** * *echo date('l, F jS Y.');
    ** * *?>
    ** *</p>
    **</body>
    </html>

    The html, in a html file works, the php in a php file works, but the total in a html file ignores the php.

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You can only use HTML in an HTML file, you can use HTML + PHP in a PHP file.

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,118
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    You can only use HTML in an HTML file, you can use HTML + PHP in a PHP file.
    That is entirely based on server setup, but that is generally true (you can setup .html to run against php although that is usually ill-advised.

    Quote Originally Posted by rdiebel View Post
    The html, in a html file works, the php in a php file works, but the total in a html file ignores the php.
    Rename your html file (the one that contains both html and php to have a .php extension and it will work.

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    you can setup .html to run against php although that is usually ill-advised.
    Why would having your HTML file run PHP be ill-advised?
    Each day is a learning experience.

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,118
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Typically changing the behavior of an extension is ill-advised (as the purpose for doing it, is unnecessary). From a disaster recovery scenario you are adding a step that really isn't needed (the need to change the behavior of an extension so it performs differently).

    On an Apache environment, sure you can use an .htaccess file to do it, so it is deployable with your code (not certain you can do that with IIS).

    I guess my point is, changing the default behavior of an extension is an unnecessary step since there are extensions that already support what you want to do.

    Now don't take my statement to mean you shouldn't perform
    PHP Code:
    <?php
    // accessed by calling index.php
    include('mytemplate.html');
    ?>
    and your mytemplate.html may very well include php tags.

    My statement is directly against using index.html as your serving page and index.html contains php tags and must go through the php parser first (not a default behavior).

  6. #6
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So your concern is a performance issue? It forces another step in the process?

    How much of a delay in loading the page is caused by this?
    Each day is a learning experience.

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,118
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    No my concern is the not obvious execution of an already defined extension (html). HTML by design does not get parsed server side. It would be like changing an .asp extension to execute against PHP. You can do it, but should you? Or a .cgi to execute against php.

  8. #8
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it. It now makes sense to this thick headed old man.
    Each day is a learning experience.

  9. #9
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,118
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Don't get me wrong, it is entirely of my own opinion and everyone can do as they wish. Also, one other small tid-bit, if you were to allow .html to run the php parser, you are in a sense slowing down html pages that have no php in them, as they are still being forced to run through the php parser first (small hit on performance, but it is a hit nonetheless).

  10. #10
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    989
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    I'd suggest there's also a usability/management issue. If another developer looks at the site, they'll see a .html file and assume it's flat HTML. This can cause a headache when it comes to tracking down code, debugging and will cause an issue if moved to another server.


Tags for this Thread

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
  •