PHP Website Development
Home | Contact Us | Sitemap

Custom Search

What is PHP?


PHP – a recursive acronym of “Hypertext Preprocessor” is an open source (means FREE!!) server side embedded scripting language for website development. Generally it is used for web pages with dynamic content that can interact with databases (web based software applications. The endless possibilities of the PHP scripting language and a great community of users have made it one of the most popular open-source languages. Open Source means it doesn't cost anything. One can use it as much as he wants and where he wants. It is capable of managing huge database-driven online environments. PHP is especially lightweight and speedy.

Technically much of its syntax is borrowed from C, Java and Perl with some its unique features. PHP code is enclosed within special PHP tags in an HTML page. When a visitor opens the page, the server processes the PHP code and then sends the output to the visitor's browser; you only need to save your file with the extension “.php”. PHP offers excellent connectivity to many databases including MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, and Generic ODBC. The popular PHP-MySQL combination (both are open-source products and FREE of cost) is available on almost every UNIX host. PHP's support for Apache and MySQL further increases its popularity. Apache is now the most-used web-server in the world. PHP can perform any task that any CGI program can do, but its strength lies in its compatibility with many types of databases. Also, PHP can talk across networks using IMAP, SNMP, NNTP, POP3, or HTTP.

Historically Rasmus Lerdorf created PHP in 1994. PHP known originally as Personal Home Pages. The parser was rewritten in mid-1995 and renamed PHP/FI version 2. The "FI" in this version stood for the Form Interpreter. PHP/FI underwent massive growth, and other people started to contribute code to it regularly. In mid-1997 Zeev Suraski and Andi Gutmans rewrote the main parser, and PHP shifted from being Rasmus' own to a more group-orientated project. This formed the basis for PHP3, now named PHP: Hypertext Preprocessor - a recursive acronym. The latest version, PHP4, is another rewrite by Suraski and Gutmans and is based around the Zend engine.




PHP Basic Syntax
 
The syntax and semantics for PHP are similar to most other programming languages like C, Java, Perl with the addition that PHP code must be contained within tags.

Example #1 Basic Structure
<?php
//....Your code goes here
?>
OR if enabled shorthand support (Can be configured from the server settings with "php.ini"    file )
<?
//....Your code goes here
?>

We can repeat above block as many times as required in a single document. The above PHP block can be embedded in normal HTML coding provided the php code must contain starting tag (<?php OR <?) and ending tag (?>)

For the php code to be executed, the file must be saved with ".php" extension.

Example #2 Printing "Hello World!"
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
echo 'Hello World!' ;   //Notice semicolon at the end of statement.
?>
</body>
</html>

If you save this file (e.g. first.php) and place it on PHP enabled server and load it up in your web browser, then you should see "Hello World!" displayed. Please notice semicolon (;) at the end of echo "Hello World!". Each statement in PHP ends with semicolon(;).

When PHP parses a file, it looks for opening and closing tags, which tell PHP to start and stop interpreting the code between them. Parsing in this manner allows php to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser. Most of the time you will see php embedded in HTML documents, as in the next example.

Example #3 Escaping from HTML
<?php
if ($expression ) {
?>
<strong>This is true.</strong>
<?php
} else {
?>
<strong>This is false.</strong>
<?php
}
?>

The basic for loop syntax is:
for (initialization; condition; incrementor) {
  code;
}
The initialization defines the loop variable and its initial value (such as $i=1). The loop will continue to iterate while the conditional expression evaluates as true (like $i<10). Each time the loop is executed, the incrementor code is exectued (the code $i++ would increment the loop variable $i by one; $i++ would increment the loop variable $i by 1 each iteration). Putting these together in a simple example,

Example #4 Basic loop structure
<?php
for($i=1; $i<=10; $i++ ){
echo $i ;
}
?>

This code would generate the output "1 2 3 4 5 6 7 8 9 10" since the variable $i starts at 1 and increments by one each loop until it is no longer less than or equal to 10.
Our other websites
Free PHP Source Code Download    Free Bollywood News & Downloads   Free Funny SMS Text Messages
 
Home | About Us | Privacy Policy | Site Map | Contact Us

Copyright © 2009-2010 PHPWEBS