Home arrow PHP arrow Page 2 - PHP3 Introduction

Getting your feet wet - PHP

Introduction to PHP and web database interfacing with MySQL. PHP3 is an HTML-embedded scripting language allowing web developers to create dynamic, database-driven websites.

TABLE OF CONTENTS:
  1. PHP3 Introduction
  2. Getting your feet wet
  3. HTML forms and variables
  4. MySQL database interfacing
By: W.J. Gilmore
Rating: starstarstarstarstar / 8
March 26, 1999

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: