« iWeb : Adding Google Analytics without editing the webpage | Main | iWeb : Another table example »

maandag, 05 juli, 2010

HTML as PHP

With a proper configuration on the server you can use webpages with a html extention as php files.

The question was raised in the iWeb forum at Apple Discussions.

Here's an explanation :

Execute PHP from a .html File

I used this :

AddType application/x-httpd-php .html

Here's a widget_markup file. You won't see anything php in the source :

http://dailynews.webege.com/phpdemo/widget1_markup.html

This is what I pasted in the HTML Snippet :

<?php
echo("hello world\n");
?>

How to create a .htaccess file on the server, read this :

http://iweb.dailynews.webege.com/PHP_parse_error.html

UPDATE

To make the server check for php code in the widget-markup files only, use this code :

<files widget*.html>
AddType application/x-httpd-php .html
</files>

And to avoid a php error with the iWeb page, make sure this line is present in the .htaccess file :

# to prevent the php parse error
php_flag short_open_tag off
Posted by wyodor at 9:34 PM
Edited on: zondag, 07 augustus, 2011 2:54 PM
Categories: Web