954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

My embedded php code won't execute


<?php

echo 'This is my first PHP web page.';

?>

techhelpforme
Light Poster
29 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

It has to end in .php to be parsed by the PHP engine, change your file name back to PrintInfo.php.

The HTML code (within the PrintInfo.php code) will not be analysed by the PHP parser, bnut instead be sent straight to output. The PHP parser only reads between the <?php and ?> tags.

Roberdin
Supreme Evil Overlord
Team Colleague
282 posts since Feb 2003
Reputation Points: 63
Solved Threads: 6
 

It has to end in .php to be parsed by the PHP engine, change your file name back to PrintInfo.php.

The HTML code (within the PrintInfo.php code) will not be analysed by the PHP parser, bnut instead be sent straight to output. The PHP parser only reads between the <?php and ?> tags.

Thanks Roberdin. Sorry I should have specified that I'm trying to make web pages with embedded php work, so I was wanting .html files to work. I found out I needed to add this line to my httpd.conf file in the Apache directory:
AddType application/x-httpd-php .html
to get apache to associate .html files with the php engine.

techhelpforme
Light Poster
29 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

Another way round to use .html is use mod_rewrite to convert .php to .html (any file format you can convert)

PoA
Posting Whiz in Training
237 posts since Jul 2004
Reputation Points: 26
Solved Threads: 9
 

The command to add to .htaccess to get html files treated as php is:

AddHandler server-parsed .html

felgall
Junior Poster in Training
50 posts since Aug 2004
Reputation Points: 13
Solved Threads: 1
 

The command to add to .htaccess to get html files treated as php is:

AddHandler server-parsed .html

Ok, I know this is an old thread but just ran across it.

How can you do the same as above in IIS. It's in the planning stages to convert to Apache but that may or may not happen.
In any case, do to some restrictions(long story) I HAVE to use .HTM as the first called document. I can use that to run into .PHP docs but it would be nice to be able to start in PHP for some dynamic forms development.

dreaogse
Newbie Poster
5 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

you can't run php code inside a .html files.... your files should be saved as .php so it will be parsed at the server.

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 
you can't run php code inside a .html files.... your files should be saved as .php so it will be parsed at the server.

Actually you can - but it means using htaccess files (as mentioned previously) or using a templating engine (e.g. Rain TPL) which stores cached php files of htmls. For everyday use, I really can't see what advantage there is to be gained from using the *.htm(l) extension if you're using server-side code.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 
Actually you can - but it means using htaccess files (as mentioned previously) or using a templating engine (e.g. Rain TPL) which stores cached php files of htmls. For everyday use, I really can't see what advantage there is to be gained from using the *.htm(l) extension if you're using server-side code.


hey ardav! you always contradict at my every post! grrr....! :@

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 
hey ardav! you always contradict at my every post! grrr....! :@


Well, ardav is correct so he is completely within his right to make a post :)

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 
hey ardav! you always contradict at my every post! grrr....! :@

Sorry VD, wasn't intentional - no vendetta, honest! Cheers Shawn.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 
Well, ardav is correct so he is completely within his right to make a post :)

you too! hey im just a newbie... and im just sharing what i know a little about php :'(

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 

Actually, if everybody would have read my post they would have seen
1. Yes you can in Apache with some .htaccess modifications.
(noted in previous posts and was a fix for the original question.)
2. I'm not running Apache, I'm running IIS so those modifications will not work in my case.
3. I have some restrictions that REQUIRE me to use a .HTM extension as a "landing page" and can pass data to PHP from a form but I HAVE to use the .HTM extension first.

In any case, we have found a work-around for this problem so I no longer need to modify the IIS server data. Thanks anyway

dreaogse
Newbie Poster
5 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 
In any case, we have found a work-around for this problem so I no longer need to modify the IIS server data. Thanks anyway

Mark it solved then.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Well, technicaly, it wasn't "solved" being that the question wasn't answered. We just decided to go another route, abandoning the idea.
Oh, and being a new person on this forum, I have no idea how to mark this "solved".

dreaogse
Newbie Poster
5 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

just aside the reply thread button.

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 

hmmm, it might be because I wasn't the originator of the post but that option is not available to me for this thread.
I even had a couple of other people look. Just in case I was missing it for some reason.

dreaogse
Newbie Poster
5 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

Fair one. A lesson to a few of us (me especially) to read the posts properly.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You