ChatterBank6 mins ago
php code on html page
8 Answers
I'm new to php and trying to insert the date onto my home page. I can do this on a .php page but inserting the same code within the body tags of an html page results in the code being ignored. Would I need to put the server details onto the page? (which I don't want to do, as it involves passwords). Any help would be much appreciated.
Answers
Best Answer
No best answer has yet been selected by liquoricemad. Once a best answer has been selected, it will be shown here.
For more on marking an answer as the "Best Answer", please visit our FAQ.<?php
echo date("l dS of F Y");
?>
Prints : "Saturday 03rd of September 2005"
Check here for the format to print the date in:
http://www.w3schools.com/php/php_date.asp
The above code worked perfectly for me on my server.
Wait a minute - I think I've misread your question. Whichever page you have this code on has to finish ".php".
You can just change this suffix of this page without adding any "server details" to the content of it. The php code only works on pages that end ".php".
echo date("l dS of F Y");
?>
Prints : "Saturday 03rd of September 2005"
Check here for the format to print the date in:
http://www.w3schools.com/php/php_date.asp
The above code worked perfectly for me on my server.
Wait a minute - I think I've misread your question. Whichever page you have this code on has to finish ".php".
You can just change this suffix of this page without adding any "server details" to the content of it. The php code only works on pages that end ".php".
Thanks, stevie21, that makes it much clearer. I know now not to write any php code to html pages. Does this mean that if I changed the index.html page to index.php, the home page that would load would be index.php? Or would I have to delete the index.html as well?
(So when the address is typed in, the index.php would load automatically?)
thanks, btw, for the link, that was helpful also!
Also make sure that any other files on your site that have links to "index.html" are amended to link, instead, to index.php
All you need to do is just rename this file to end "php" : dead easy if you have ftp access or a "control panel" with your webhost.
If you just type in the address as www.stevie21.com without specifying the filename and you still are sent to the "html" file then all you have to do is amended the file pointed to (or at worst, replace the html file with one that includes a redirect)
All you need to do is just rename this file to end "php" : dead easy if you have ftp access or a "control panel" with your webhost.
If you just type in the address as www.stevie21.com without specifying the filename and you still are sent to the "html" file then all you have to do is amended the file pointed to (or at worst, replace the html file with one that includes a redirect)
-- answer removed --