PHP
  Home arrow PHP arrow Page 2 - JV’s Power Tips for PHP (1)
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

JV’s Power Tips for PHP (1)
By: Justin Vincent
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 3
    2003-01-29

    Table of Contents:
  • JV’s Power Tips for PHP (1)
  • Never Breaking Out of PHP
  • Basic Template Theory
  • Refining the Previous
  • Accessing Other Variables from Within this Type of Template
  • Using Objects to Store Multiple Output Values
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    JV’s Power Tips for PHP (1) - Never Breaking Out of PHP


    (Page 2 of 7 )

    Hmm. What other useful tips can I think of for you?

    Lets see…. Ah. I know…. Don’t break out of PHP tags at any point (period). This is a practise I carry out religiously and here’s why:

    Oh how awful:

    <?php $php_tags = “PHP Tags” ?>
    Combining HTML output and
    <?php echo $php_tags; ?>
    tags really wastes my time.


    Oh what beauty:

    <?php
      $php_tags = “PHP Tags”;
      echo “Never breaking out of $php_tags is much less irritating.”;
    ?>


    You should probably know... the advice I have just given is highly controversial. There are programmers out there reading this who are foaming at the mouth, jumping up and down, stomping on the ground and yelling ‘that’s not right!’.

    That’s because PHP takes slightly longer to execute when working this way, but when I say ‘slightly’ I do mean ‘slightly’. We’re talking milliseconds. Even with complex scripts. A user on a 56k modem or even a T1 on the other side of the world will not notice the extra execution time when data transfer is taken into consideration. Yet there are ‘many’ benefits to working this way, some of which I will outline within this article.

    If the truth be known every PHP site that I have ever written (including many that are highly complex and generate millions of hits) have been created using this style of coding. The bottleneck (if there has ever been one) has always been the ‘database server’ never the PHP. So lets not start a flame war over this. Please recognize that this is my opinion and all are free to take or leave it as they wish.

    Now that I have that out of the way let us continue.

    Working this way can bring up other (more technical) issues. Like what do you do when you want to output big blocks of HTML without having to put a \ behind all the “’s? Here’s how:

    <?php

    $turkeys = “variables”;

    print <<<END
      It is nice to know that “you” can print any amount of text on
      <font color=”red”>multiple</font> lines with <b>any</b>
      character and still include $turkeys.
    END;

    ?>


    By the way, within this article I will be jumping from one way of doing things to another. Usually I will show you what I consider to be the most understandable (not necessarily the best) way of doing something and then refine it into code that is more elegant (yet not so easy to understand). It might take two or three steps to get from understandable to elegant, but you can rest assured that each step will help to broaden your understanding of PHP and PHP techniques (unless you’re a Turkey).

    More PHP Articles
    More By Justin Vincent


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway