html to php
Posted: Mon Sep 03, 2007 9:00 pm
Can I convert any html file to php?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$html = file_get_contents('htmlfile.html');
///
$html = '<div>This is Html</div>';
///
?>
<div>This is Html</div>
<?php
///
That's the right answer! It's rather pointless to "convert" HTML to PHP unless you are going to use PHP to pre-process something, though. The web server will just parse it, find no PHP code and deliver it to the requesting browser.scottayy wrote:Yes. Just change the extension from .html to .php
Code: Select all
<?php
echo 'content of file'
//or
print ''
?>Then just put the html code in echo and that brings php from html???Rovas wrote:Just putCode: Select all
<?php echo 'content of file' //or print '' ?>
It is far better and useful to change it to .phps... It needs this directive in Apache config file:scottayy wrote:Yes. Just change the extension from .html to .php
Code: Select all
AddType application/x-httpd-php-source .phpsNEVER DO THIS ON PRODUCTION SERVERS. THIS IS A SECURITY RISK AND A BAD RECOMMENDATION.VladSun wrote:It is far better and useful to change it to .phps... It needs this directive in Apache config file:Code: Select all
AddType application/x-httpd-php-source .phps
Ooops, my mistake - I read the topic as "Convert PHP to HTML", i.e. show PHP code as HTMLEverah wrote:NEVER DO THIS ON PRODUCTION SERVERS. THIS IS A SECURITY RISK AND A BAD RECOMMENDATION.VladSun wrote:It is far better and useful to change it to .phps... It needs this directive in Apache config file:Code: Select all
AddType application/x-httpd-php-source .phps
Exposing the PHP code behind your pages is a bad move. This directive should never be set in production environments.
Not sure I understand what you are asking here. If the server does not know what to do with a .phps file extension, it will show a .phps file as plain text. However, you do not put .phps files on the server, you put .php files on the server, so the server, not knowing what to do with a .phps file looks for it, cannot find it, and returns a 404.VladSun wrote:Suppose, I have *.phps files on a server. With or without this directive the source will be exposed - do you agree? So, using this directive doesn't involve any security risks.
I agree that naming a php file .inc is stupid. For that, you could name it .txt and have the same protection. I am not sure what this has to do with the include function though.VladSun wrote:It's the same case as with *.inc.php files - the shouldn't be named *.inc, but nobody says "DON'T USE EVIL INCLUDE() FUNCTION!"