I have a website which has about 30 pages. They are all static html. But now I decided to add a news feature which should display latest article on all pages. Is there any way I can include php code in static html pages? because I don't really want to change 30 pages into php.
Including php in Html pages
Change the file extension from .html to .php so the files are now effectivly php files, and will be parsed as such.
Don't worry, this won't effect how your page displays, because php files contain straight HTML in them anyway. You just seperate the HTML from the php code using the php tags :<? ?>
So just find a spot in your code HTML where you want the news to go, and just put in the php code:
<html>
<body>
<p>fjldsj</p>
etc..
<? include("news.php"); ?>
</body>
</html>
where news.php is a php file that displays the news or article or whatever.
If you are super lazy and don't want to change the file extensions (which is not really much work at all), then you can configure php to parse .html files.
This would mean that you could include whatever php code you like in .html files, as they will be parsed with the php engine. However this isn't recommended, cause it slows down the processing of html files that don't include any php, as they must also be parsed by the php engine regardless.
You can configure php to parse .html files by editing your php.ini. I forget the actual bit you edit, but it's clearly marked in there.
cya
-Adam