html to php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

asif_phpdn
Forum Commoner
Posts: 28
Joined: Sun Aug 26, 2007 8:50 pm

html to php

Post by asif_phpdn »

Can I convert any html file to php?
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Convert Html to PHP?

Code: Select all

$html = file_get_contents('htmlfile.html');
///
$html = '<div>This is Html</div>';
///
?>
<div>This is Html</div>
<?php
///
??
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Yes. Just change the extension from .html to .php ;)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

scottayy wrote:Yes. Just change the extension from .html to .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.
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post by Rovas »

Just put

Code: Select all

<?php
echo 'content of file' 
//or 
print ''
?>
asif_phpdn
Forum Commoner
Posts: 28
Joined: Sun Aug 26, 2007 8:50 pm

Post by asif_phpdn »

Rovas wrote:Just put

Code: Select all

<?php
echo 'content of file' 
//or 
print ''
?>
Then just put the html code in echo and that brings php from html???
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If the HTML pages are not going to have any PHP in them do not just name them PHP. They will go through the parser, be read, then returned to the user agent through the web server. If the pages are going to stay static, let the server serve them directly. It will be faster and better overall.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

scottayy wrote:Yes. Just change the extension from .html to .php ;)
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
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

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
NEVER DO THIS ON PRODUCTION SERVERS. THIS IS A SECURITY RISK AND A BAD RECOMMENDATION.

Exposing the PHP code behind your pages is a bad move. This directive should never be set in production environments.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Everah wrote:
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
NEVER DO THIS ON PRODUCTION SERVERS. THIS IS A SECURITY RISK AND A BAD RECOMMENDATION.

Exposing the PHP code behind your pages is a bad move. This directive should never be set in production environments.
Ooops, my mistake - I read the topic as "Convert PHP to HTML", i.e. show PHP code as HTML :)

But ... one should never say "never" ;)
What about having a PHP example on a production server ;) Using .phps is the easiest and elegant way to view syntax colored PHP source :)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

highlight_file(), without making changes to your server settings.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

@Everah
I can't agree with you.
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.
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!"
Your post is a little bit of FUD ;)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

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.
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: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!"
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.

If you want people to be able to see the source of your application code, by all means go ahead and turn that feature on for your servers. But offering the advice to people here to open up their code on their servers is irresponsible. It is a security risk. Everything that is in a PHP file becomes exposed if the .phps directive is turned on.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

They can't see it if it is *.php file... They would be able to see it if it is *.phps file (thats the analogy with *.inc and *.inc.php). So where is the security issue?
One need to rename a .php file to .phps file to make this directive applied. That's why having this directive turned on is not a security issue.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply