944,195 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 22466
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 10th, 2004
0

My embedded php code won't execute

Expand Post »
This works:

-----------PrintInfo.php
<?php
phpinfo();
?>
--------------------------

But this doesn't:

-------------PrintInfo.html
<html>
<head>
<title> Hello World </title>
</head>
<body>
<?php

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

?>
</body>
</html>
-------------------------

I'm using Apache 2.0 on WinXP Home with php 5.

Thanks!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
techhelpforme is offline Offline
29 posts
since Aug 2004
Oct 10th, 2004
0

Re: My embedded php code won't execute

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.
Team Colleague
Reputation Points: 63
Solved Threads: 6
Supreme Evil Overlord
Roberdin is offline Offline
282 posts
since Feb 2003
Oct 10th, 2004
0

Re: My embedded php code won't execute

Quote originally posted by Roberdin ...
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
techhelpforme is offline Offline
29 posts
since Aug 2004
Oct 10th, 2004
0

Re: My embedded php code won't execute

Another way round to use .html is use mod_rewrite to convert .php to .html (any file format you can convert)
PoA
Reputation Points: 19
Solved Threads: 9
Posting Whiz in Training
PoA is offline Offline
234 posts
since Jul 2004
Oct 11th, 2004
0

Re: My embedded php code won't execute

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

AddHandler server-parsed .html
Reputation Points: 13
Solved Threads: 1
Junior Poster in Training
felgall is offline Offline
50 posts
since Aug 2004
Jan 5th, 2010
-1
Re: My embedded php code won't execute
Click to Expand / Collapse  Quote originally posted by felgall ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dreaogse is offline Offline
5 posts
since Sep 2009
Jan 6th, 2010
0
Re: My embedded php code won't execute
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.
Reputation Points: 32
Solved Threads: 64
Posting Pro
vaultdweller123 is offline Offline
509 posts
since Sep 2009
Jan 6th, 2010
0
Re: My embedded php code won't execute
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.
Sponsor
Featured Poster
Reputation Points: 1067
Solved Threads: 954
Disgraced Poster
ardav is offline Offline
6,730 posts
since Oct 2006
Jan 6th, 2010
0
Re: My embedded php code won't execute
Click to Expand / Collapse  Quote originally posted by ardav ...
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....!
Reputation Points: 32
Solved Threads: 64
Posting Pro
vaultdweller123 is offline Offline
509 posts
since Sep 2009
Jan 6th, 2010
0
Re: My embedded php code won't execute
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
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: 2 where clauses in mysql query
Next Thread in PHP Forum Timeline: Need a script to backup database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC