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!

Recommended Answers

All 17 Replies

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.

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.

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

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

AddHandler server-parsed .html

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.

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.

Member Avatar for diafol

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.

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

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 :)

Member Avatar for diafol

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

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

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 :'(

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

Member Avatar for diafol

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.

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

just aside the reply thread button.

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.

Member Avatar for diafol

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.