Jump to content

How to parse PHP in html


drums

Recommended Posts

What would the code be to display server side code like the date and time to display in html pages? I have the date code for copyrights that I want to display

<?php echo date(Y); ?>

and I think I need to create an .htaccess file to put it in but not sure what to put.

Thanks,

Link to comment
Share on other sites

Ah, you're wanting to force the html page to parse as php?  You can do this in .htaccess, yes, add this line:

 

AddType application/x-httpd-php .html

 

If that doesn't work, here's a handful of other methods:

 

http://www.velvetblues.com/web-development-blog/how-to-parse-html-files-as-php/

 

This will make the server treat any file with the .html extension as if it had the .php extension.

Link to comment
Share on other sites

If you look at the source code you'll see that it's printing "Copyright © <?php echo date("Y"); ?> - The Veitch Law Firm – All Rights Reserved" - which means that the page is not being parsed as PHP.  Either the functionality is disabled on your server, or you might need to try one of the other methods on that link I sent.

Link to comment
Share on other sites

  • 2 months later...

I have tried the htaccess lines in the suggested link (good information).  But I still can't get the PHP tags to work in HTML.

 

I am using GoDaddy Deluxe with Linux Grid & PHP5. (I think this is new and different from the godaddy example in the referenced link).  I think the Deluxe Grid uses the "cgi" part and the php5 is a little different than the other php.

If I leave the cgi off .php files still work

If I leave the "5" off the php the .php files still work

If I add any AddType then the .html files don't work

 

See the following test pages:

http://hexpanse.com/dev/phpworking.php (works)

http://hexpanse.com/dev/phpworking.html (not working)

http://hexpanse.com/dev/layoutwithphp001.php (php gives syntax error on <?MLS version tag)

I am using the following .htaccess file:

AddType image/svg+xml .svg .svgz

AddEncoding x-gzip .svgz

AddHandler x-httpd-php5-cgi .php

AddHandler x-httpd-php-cgi .php4

I got the last two php lines from this GoDaddy support page:

http://community.godaddy.com/help/article/1082

I believe that I should be using php tags inside of .html files, and not the other way around.

 

- Go Daddy support says don't do customer support for help with running scripts, and referee me to the help/support pages.  Some of the other support posts there are using different set ups.  But here is one that is close:

http://community.godaddy.com/groups/web-hosting/forum/topic/php-using-html-file-extension/#post-95463

 

Please advise  - thanks you for any help!

 

Troy McGee

troy@troymcgee.com

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.