PHP
  Home arrow PHP arrow Page 2 - JV’s Power Tips for PHP (2)
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  
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 (2)
By: Justin Vincent
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2003-02-02

    Table of Contents:
  • JV’s Power Tips for PHP (2)
  • The Problem
  • Method 1
  • Method 2
  • Method 3
  • Method 4
  • 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 (2) - The Problem


    (Page 2 of 7 )

    We all want to get things done and there are many ways to skin a cat. For example: Imagine you were writing a live chat script and you wanted to give the user the option of formatting each submission with any combination of Bold, Italic, Underlined and/or Strike Through. Here is an example HTML form for such a script:

    <form method=post action=my_script.php>
    <input type=text name=chat>
    <input type=checkbox name=bold value=1>
    <input type=checkbox name=italic value=1>
    <input type=checkbox name=underline value=1>
    <input type=checkbox name=strike value=1>
    <input type=submit>
    </form>


    Since this form has the action of post we will be evaluating the following variables:

    $_POST['chat']
    $_POST['bold']
    $_POST['italic']
    $_POST['underline']
    $_POST['strike']


    At its most basic we can test if the user has selected bold by doing this:

    <?php

      if ( $_POST['bold'] )
      {
        echo "The user selected bold";
      }

    ?>


    Just in case you don't know why this works. It is because if the bold checkbox was selected, then the value of 1 will be sent to PHP (within the variable $_POST['bold'])., but if the bold checkbox was not selected then the variable $_POST['bold'] will not be sent to PHP at all.

    Furthermore, in PHP you are able to put a single variable into an if statement. The if statement will then evaluate the contents of the variable. It will evaluate to false under the following conditions:

    1. The variable does not exist
    2. The variable exists with a value of nothing
    3. The variable exists with a value of 0
    4. The variable exists with a boolean value of false
    5. The variable exists with a value of NULL
    It will evaluate to true under the following conditions:

    1. The variable exists and has ANY value except empty, 0, NULL or false.
    You can also evaluate an assignment within an if statement. Like so:

    <?php
      $i_am_false = false;

      if ( $make_me_false = $i_am_false )
      {
        echo "This will never be output!";
      }
      else
      {
        echo ‘Because $make_me_false was assigned the value of false';
      }
    ?>


    You can also put an array or an object within an if statement.

    <?php

      if ( $my_object )
      {
        echo "My object exists!!";
      }

      if ( $my_array )
      {
        echo "My array exists!!";
      }

    ?>

    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 2 hosted by Hostway
    Stay green...Green IT