PHP
  Home arrow PHP arrow Page 2 - PHP3 Introduction
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
Google.com  
PHP

PHP3 Introduction
By: W.J. Gilmore
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    1999-03-26


    Table of Contents:
  • PHP3 Introduction
  • Getting your feet wet
  • HTML forms and variables
  • MySQL database interfacing

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    PHP3 Introduction - Getting your feet wet
    ( Page 2 of 4 )

    Again, PHP3.0 commands can be easily inserted alongside HTML. This provides an easy way to incorporate dynamic information within what was previously a static document. For example, if we would like to insert the current date into the HTML document that visitor has called, we might do the following:



    <HTML> <HEAD> <TITLE>Our first PHP3.0 script</TITLE> </HEAD> <BODY> <CENTER>Our first PHP3.0 script</CENTER> <? /* the above "<?" signals that the PHP script has begun */ $today = date("Y-m-d"); PRINT "<CENTER>Today is: $today.</CENTER>"; # the following "?>" closes the script ?> </BODY> </HTML>


    Assuming today is August 27, 1998, our output would be:

    Our first PHP3.0 script

    Today is: 1998-08-27.


    A few points to make:
    1. All PHP3.0 commands must be enclosed within the "<?" and "?>" brackets. A second method to denote PHP3.0 commands is by enclosing them within "<?php...?>" brackets.
    2. Comments can be made within the script, and are enclosed within "/*" and "*/" brackets, or by placing a "#" sign at the beginning of the line.
    3. All statements that are to be outputted to the screen must be enclosed in double quotations ("), and led by the PRINT statement.
    4. Almost every PHP3.0 command must end in a semi-colon (;).
    5. Any HTML commands placed within the PRINT statements will be interpreted by the browser, and perform their usual actions.
    6. Documents including PHP3.0 statements must be saved with the extension *.php3 (For example, myphpfile.php3). This tells the PHP3.0 interpreter to execute any commands found within the script.
    7. In short, the date command operates as follows:
      Syntax: string date(string format, int timestamp);

      The function can take two variables (timestamp) is optional. If supplied with a timestamp, the function returns a string containing a date formatted according to the parameters within the format string. In the above example, Y-m-d signifies year, month, and day, respectively, all in numerical format. There are many other format characters that can be placed within the format string. For a complete list, click here.


    The include statement
    Another very powerful use of PHP3.0 is the capability of building HTML templates, which are very useful when one is developing a cohesive site with many pages. Let's assume one would like to place a footer at the bottom of each page, for example:

    Copyright © 1997-99 ngenuity. All rights reserved.


    But what happens when the site increases in size to say 50 pages, and suddenly the footer must include another statement? This would involve the modification of each page, one by one, taking up a lot of time and effort.

    However, PHP3.0 offers the include statement, which allows one to include a separate file within an HTML document. Let's insert the above copyright statement into a separate text file, and save it as "footer.txt". Then, one only has to insert the following command at the bottom of the HTML file:


    <? include("footer.txt")?>

    and the footer will appear when loaded into the browser! Supposing the site grows to 50 pages, and that copyright needs to be modified. The only step the developer has to take is to open the footer file, make the necessary modification, and Voila!. 50 pages are immediately updated.

    Interesting, huh? Now, let's look at some of the more dynamic aspects of the language, incorporating HTML forms and variables passing/modification.


     
     
    >>> More PHP Articles          >>> More By W.J. Gilmore
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek