|
-
Nov 15th, 2006, 05:03 PM
#1
Re: Single, Double Quote Trouble
 Originally Posted by kzatu
So someone on this forum recommended that I print all HTML through echos. So I rewrote my entire code to do so and it's been humming with precision ever since. So I imagine there might be something less desirable about echoing HTML, but it hasn't reared its ugly head yet. Would you mind expanding on this?
Whoever told you that should be shot. Have a read of this:
http://www.vbforums.com/showpost.php...49&postcount=7
The reason you cannot send a header after you have written data, is because it is a header. It should come before everything else. As soon as you send HTML or any other kind of output, the headers are flushed.
The best way around this is to write your scripts properly. Tehre is no reason why a small script cannot use the MVC (model-view-controller) design pattern, all be it, slightly cut down and you do not need to be an experienced coder.
Simply split your scritps into two parts:
Code:
Database / File (view) <--------> (Part 1 - controller) Input Processing and Data Processing
- do all processing and load any data to be displayed into array
- DO NOT produce any output here
(Part 2 - view) This is where you send your headers
(before HTML output) and finally output your HMTL.
- use only simply display logic here and loops
Using this method you can keep all your output separate and if need be change the output to say WML, Javascript or even plain text. It also allows you to inependently maintain the controller that accesses the database.
Its an easy pattern to follow and the small, extra investment in time more than pays for itself.
Th other very crude method you could use it simply open an output buffer at the beginning of your script. This causes all output to be stored and only flushed at the end of the script. I don't recommend this because it encourages poorly wirrten scripts:
PHP Code:
<?php ob_start() ?>
If you use echo to produce HTML output you are shooting yourself in the foot. It makes your scripts harder to maintain, hard to read, un scalable, in-flexible and it makes the person who wrote them look incompetent.
Last edited by visualAd; Nov 15th, 2006 at 05:06 PM.
-
Nov 15th, 2006, 05:11 PM
#2
Thread Starter
Addicted Member
Re: Single, Double Quote Trouble
If you use echo to produce HTML output you are shooting yourself in the foot. It makes your scripts harder to maintain, hard to read, un scalable, in-flexible and it makes the person who wrote them look incompetent.
Hey I resent that last sentence! (j/k). You're lucky that you are catching me while I'm still young and malleable.
I'm going to mark this complete now. Thanks guys.
Changes are not permanent, but change is. {Neil Peart}
-
Nov 15th, 2006, 05:18 PM
#3
Re: Single, Double Quote Trouble
 Originally Posted by kzatu
Hey I resent that last sentence!  (j/k). You're lucky that you are catching me while I'm still young and malleable.
I'm going to mark this complete now. Thanks guys.
None of my comments are personal. But I can direct them at you upon special request and upon transfer of $100 to my paypal account
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|