BH, I'm a web designer. Of course I'm completely sure. Let's say you have a bunch of web pages like this: index.html, about.html, contact.html
Just rename the files to this: index.php, about.php, contact.php
If you are using dreamweaver or any other web editor, do the renaming inside the editor. This will update any links automatically. For instance if your logo is linking to the homepage, it won't work anymore if you do the renaming manually unless you go inside the code and update the link as well. If you want to do the renaming manually and can't see the file extensions then you need to change your computers settings to display file extensions.
If you rename index.html to index.php what is happing is that you are telling the browser on clients machine that this is a php file and any php code inside the file should be executed. If there are no php codes inside the page, then the browser will look inside and do nothing except loading the page normally as it would do if it was index.html.
I usually start building my website in html file format. Then after I have the header and footer sections ready, I move them to separate mini pages and include those mini pages inside each main page. Those mini pages are called PHP includes.
This is how it works:
1. Inside my main directory I create a folder called
includes.
2. Inside that folder I create a file called
menu.html but this file is comnpletely blank. It does not have any head, body sections etc. You can open notepad and save the blank file as menu.html inside the includes folder.
3. Then I go to my index.html page and cut all the section that is related to the menu and paste it to the menu.html file I just created.
4. Now, there is no menu in the index.html file because I moved it to an external file. Therefore I need to include the menu.html file inside my index file. To do this I put this code inside the index file where the menu code used to be:
Code:
<?php include("includes/menu.html"); ?>
5. As you see the above says, include the menu.html file inside this file. The problem is, this is a PHP code but I have an index.html file. What should I do now? Of course I just rename my index.html file to index.php file and now it works. (This will work on the website after you have uploaded the new files to your host. It wont work on your local machine, unless you have installed a local server on your computer for testing purposes, which I did).
6. Now you can go ahead and do the same to all your files that have the menu. What is the advantage? The advantage is that, when you need to change the menu you only change and upload the menu.html file and all your pages will be updated. You can of course use Dreamweaver templates instead PHP includes but then you have to upload all your pages.
7. I usually create PHP includes for the header, menu footer and head sections. The head section is an area inside the head tags that includes meta tags and site name. Basically, whatever is common in all pages, gets to be moved to PHP includes. If there are any pages on the site that don't have any PHP code inside them you just rename them to PHP as well, because otherwise your site will look amateurish.
8. If your links don't work after you have moved the menu or footer to an included file, then change your links to absolute links instead relative links. If you don't know this post here and I will explain.
Two small notes:
1. Nick, who posted earlier in this thread was spot on.
2. The title for this thread should be "How to convert an
HTML page to PHP?".
Erdinc