Page 1 of 1

<?php...?> in html code ignored

Posted: Fri Jul 10, 2009 11:48 am
by scott1944
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

Re: <?php...?> in html code ignored

Posted: Fri Jul 10, 2009 11:58 am
by andyhoneycutt
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

Re: <?php...?> in html code ignored

Posted: Fri Jul 10, 2009 12:01 pm
by genconv
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.

Re: <?php...?> in html code ignored

Posted: Fri Jul 10, 2009 12:10 pm
by genconv
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

Re: <?php...?> in html code ignored

Posted: Fri Jul 10, 2009 4:01 pm
by scott1944
Many thanks for responses. I will do as you suggest.
scott