Forum Moderators: mack
However, my main priority is to optimize the site and put up Adsense. And if PHP is going to complicate this process (not to mention the steep learning curve) then I think I'll give it a miss and stick to HTML.
For those who have taken this road, what are the cons in using PHP for what I'd like to do?
This:
<?php echo "<p>Hello</p>";?>
Produces the same thing as:
<p>Hello</p>
The difference of course is <p>Hello</p> can be a variable, calculation, the time etc...
----------------
Not sure what you mean by optimize but if you are referring to say management of a site this is another thing you can use php for. For example instead of placing your ads directly in the HTML you can instead include them in documents.
<?php include($_SERVER['DOCUMENT_ROOT'] . '/somefolder/adcode.php');?>
Place your ad code into adcode.php , use the include statement in documents where you want to place the ads. the benefit of this is if you want to change the ad you only have to edit adcode.php , everywhere you have used the include it will take affect. This method can also be applied for parts of your pages that you want to be the same site wide such as navigation and footers.
I've seen a lot of debate on whether (index.php?article=1 , index.php?article=2) is equally affective as (article1.html , article2.html) , I really don't think it makes much difference if any. If it's really a concern you can research rewriting the URL's with htaccess.
require ('filename.php');
Which is invaluable to me now, along with CSS it makes it extremely easy to edit parts of pages that are consistent, like headers, navigation links, footers etc..
The *only* drawback I've noticed is that you can't easily preview locally, but that is why I make it in HTML / CSS first and preview a template page, then cut / paste the code into other files and make the PHP code.
php doesn't have to have url's like that. Assuming your using apache you can use mod_rewrite to make the urls anything you want.
For example you might have something like this on a php site.
http://example.com/index.php?post_id=543
You can use mod_rewrite to make the url look like this
http://example.com/post/543/the-title-of-the-post-for-seo-reasons
Here's an example from my blog, it's not php, but it's dynamic (not html) and the same concept. Notice the seo friendly url.
<url removed>/post/show/69541/Just-enough-emacs-for-lisp
One of hte benefits of using php over html is that you can avoid duplicating work. For example your nav bar on a plain html site will be in every single html file. When you want to change something you have to change it in many places which leads to mistakes. With php you can avoid that duplication and save yourself a lot of time and headaches.
[edited by: encyclo at 11:52 pm (utc) on July 19, 2007]
[edit reason] no links to personal sites please [/edit]
What would you recommend? The PHP for Dummies books? A course? Some websites?
Like you I have used many example scripts found on the Internet but I find out how and why they work instead of simply copying and pasting. You can pick up many examples and lot of information on php.net in the manual.