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
scott1944
Forum Newbie
Posts: 2 Joined: Fri Jul 10, 2009 11:39 am
Post
by scott1944 » Fri Jul 10, 2009 11:48 am
Embedding html in my php files works fine. Embedded php in an html file is ignored. For example, the following produces a blank page but with the head processed. Indeed, all html code is processed and no php code is. Any help offered will be much appreciated.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title> Messing about </title>
</head>
<body>
<p>
<?php
echo 'hello world';
?>
</p>
</body>
</html>
many thanks
scott
andyhoneycutt
Forum Contributor
Posts: 468 Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls
Post
by andyhoneycutt » Fri Jul 10, 2009 11:58 am
Is your file a .html file or a .php/.php5 file?
If the former, you'll want to add a directive to apache telling it to process html for php. Otherwise, change it to a .php/.php5 file.
-Andy
genconv
Forum Commoner
Posts: 34 Joined: Sun Jul 05, 2009 9:27 am
Post
by genconv » Fri Jul 10, 2009 12:01 pm
This is because PHP parser don't parse HTML files (this is default). If you want to parse .html files you must to add this line:
Code: Select all
AddHandler application/x-httpd-php .html
to the php configuration file.
genconv
Forum Commoner
Posts: 34 Joined: Sun Jul 05, 2009 9:27 am
Post
by genconv » Fri Jul 10, 2009 12:10 pm
You can also add this line to the .htaccess file:
For Web servers using PHP as apache module:
Code: Select all
AddType application/x-httpd-php .html
For Web servers running PHP as CGI:
Code: Select all
AddHandler application/x-httpd-php .html
scott1944
Forum Newbie
Posts: 2 Joined: Fri Jul 10, 2009 11:39 am
Post
by scott1944 » Fri Jul 10, 2009 4:01 pm
Many thanks for responses. I will do as you suggest.
scott