Home arrow PHP arrow Page 2 - PHP 101 (Part 1) - Secret Agent Man

Bond...James Bond - PHP

PHP is the hottest scripting language around - and with the release of PHP4, more and more developers are looking at it as a rapid Web development tool. This new series of tutorials is aimed at getting novice programmers up to speed on the language, and the first article covers variables, operators and the include() function call. Exploding chewing-gum is optional.

  1. PHP 101 (Part 1) - Secret Agent Man
  2. Bond...James Bond
  3. A Case Of Identity
  4. The Toy Shop
  5. Weapons To Die For
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 36
July 31, 2000

print this article


Once you've configured your Web server to parse PHP pages, it's time to test it and see if everything's working as advertised. The simplest way to do this is to pop open your favourite text editor and create a file containing these lines of code:

<?php phpinfo(); ?>
Save the file with the extension .php - for example, "test.php"

Now, start up your Web browser and point it to the file you just saved - for example, http://localhost/test.php - and you'll see a page filled with what at first glance appears to be gibberish, but on closer inspection will reveal itself to be a list of internal PHP variables. The values of most of these variables can be modified by altering the "php.ini" file that ships with every distribution of PHP. For beginners, the default values are more than sufficient to work with.

There's one essential concept that you need to get your mind around before we proceed further. Unlike CGI scripts, which require you to write code to output HTML, PHP lets you create embed PHP code in regular HTML pages, and execute the embedded PHP code when the page is requested.

These embedded PHP commands are enclosed within special start and end tags - here's what they look like:

<?php ... PHP code ... ?> or the shorter version <? ... PHP code ... ?>
Here's a simple example which demonstrates how PHP and HTML can be combined:

<html> <head> <title>Bonding With PHP</title> </head> <body> So who do you think you are, anyhow? <br> <?php // this is all PHP code echo "<b>The name's Bond...James Bond!</b>"; ?> </body> </html>
And if you browse to this page through your browser and take a look at the HTML source, this is what you'll see:

<html> <head> <title>Bonding With PHP</title> </head> <body> So who do you think you are, anyhow? <br> <b>The name's Bond...James Bond!</b> </body> </html>
Every PHP statement ends in a semi-colon - this convention is identical to that used in Perl, and omitting the semi-colon is one of the most common mistakes newbies make. It's also possible to add comments to your PHP code, as we've done in the example above. PHP supports both single-line and multi-line comment blocks - take a look:

<?php // this is a single-line comment /* and this is a multi-line comment */ ?>

>>> More PHP Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- 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: