Been using PHP for about a year now and still learning. Had a question about programming with php though...
Is it better to just do the whole source with PHP and using "echo" for html codes? Or is it the "thing to do" now to only php certain parts that you need interactivity for, and use html without the php's echo command for the static parts of the page? I hope this makes sense.
php whole source?
Moderator: General Moderators
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: php whole source?
It's not a good idea to put everything in echos for a couple of reasons:
index.php
template.html
If you want to get really fancy, check out the Model-View-Controller framework (MVC)
http://en.wikipedia.org/wiki/Model%E2%8 ... Controller
- It uglys up the code
- Performance. Anything outside of the <?php ?> tags is not processed by PHP, so there's less load that way
index.php
Code: Select all
<?php
//do something cool
$title = 'Viewing item #' . $_GET['product_id'];
$desc = getDescription($_GET['product_id']); // some function to access the db
include('template.html');Code: Select all
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h2><?php echo $title; ?></h2>
<h5>Description</h5>
<p><?php echo $desc; ?></p>
</body>
</htmlhttp://en.wikipedia.org/wiki/Model%E2%8 ... Controller
-
ZachsCompServ
- Forum Newbie
- Posts: 15
- Joined: Thu Aug 26, 2010 11:29 pm
Re: php whole source?
I figured it would be better to do php only when needed. Thanks. I'll check out the other suggestions as you mentioned later on.