Forum Moderators: mack

Message Too Old, No Replies

What are the cons of using PHP with HTML?

         

pigsinpink

8:47 am on Jul 15, 2007 (gmt 0)

10+ Year Member



I've only had experience designing pages with HTML. But lately, I've become interested in some of the fancy stuff people can do with PHP ... and I'm curious to find out and try it. I'm interested in learning PHP & using small snippets of it in the HTML pages that I'm writing up for a new site.

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?

thecoalman

2:50 am on Jul 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's no cons. Simply put php extends the capabilities of what you can do with HTML.

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.

pigsinpink

3:02 am on Jul 16, 2007 (gmt 0)

10+ Year Member



Hi Coalman,

By optimize I mean search engine optimization or SEO. I know spiders don't like things with?%! in the URL, and that's one problem with using PHP/MySQL. But is there anything else that I should be aware of?

thecoalman

3:51 am on Jul 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The issues is not that they don't like them, it's that they will follow them. This is not a problem as long as you don't start getting into duplicate content generated though pagination or other things.

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.

draggar

1:33 am on Jul 17, 2007 (gmt 0)

10+ Year Member



php gives you the

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.

thecoalman

3:53 am on Jul 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To preview locally you can install easyphp , there's other similar software packages. Installs and configures apache, php, mysql and phpmyadmin . It's pretty much a one step install and you don't have to know much to get it running.

jshen

10:23 pm on Jul 19, 2007 (gmt 0)

10+ Year Member



"I know spiders don't like things with?%! in the URL, and that's one problem with using PHP/MySQL."

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]

Lokutus

5:07 pm on Jul 23, 2007 (gmt 0)

10+ Year Member



I'm in the same boat almost as the OP here. My question is how to best learn PHP? I'm asking as someone who is not a pcoder by nature. I have learned html but still rely on third parties for any PHP work that occasionally has to be incorporated.

What would you recommend? The PHP for Dummies books? A course? Some websites?

thecoalman

6:26 pm on Jul 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not one for reading books myself unless its for pleasure and prefer to learn by example, that's not to say a book couldn't be beneficial for others.

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.