PHP - Building Web Pages

PHP was designed in 1995 by Rasmus Lerdorf because it needs a free tools to program Web pages and released under the name PHP/FI, (Personal Home Pages / Form Interpreter),.
He has developped it further with the help of other programmers and made it open source for the community of users. A new engine was created for PHP 3 and a new name given: PHP Hypertext Preprocessor in 1997. The Zend engine was created in 1999 for PHP 4.
PHP 5 was released in 2004, it is more object-oriented and supports XML.
A PHP script produces web pages, and may be embedded inside HTML code as JavaScript but works server side. It is similar to C, but dynamic variables and more prototype based. A server must be configured to execute the interpreter on pages with .php extensions, and to send resulting modified HTML pages on the network.
PHP is the P of LAMP, a popular architecture that includes the Linux operating system, the Apache server and the MySQL database manager.
A project to port PHP to .NET exists and is named Phalanger.

Features

- All those of C, but typed variables, plus:
- Object oriented.
- Dynamic untyped variables prefixed by $.
- Associatives arrays (tables with keys).
- A foreach construct to scan arrays and iterators.
- Lot of APIs dedicated to the standard of the web and databases.

The language

Syntax

The langage is not case-sensitive.
Floating point numbers are denoted by a dot followed by a number or zéro.
Variables are prefixed with a $ symbol and no type is specified in advance.
Literal string which use the "" notation are evaluated for variables and numbers.

Some symbols:

<?php and ?> must enclose a PHP program.
# or // starts a comment.
array( "1" =>" "a, ...) is a dictionary.

Control structures

The if structure has elsif and else options.

if(x < 10)
{ echo "$x less than 10\n"; }
else { echo 'etc...\n' }
The while structure:
while(expr)

{
    ... 
} 

Function or method

The definition starts with the function keyword, followed by the name and the list or arguments separated by commas, and the body is enclosed between { and }.
The return keyword in the body of the definition allows to return one value.

function funcname( arguments )
{
...statements... return(x);
}

Class

class name

{
    ...
}

The body is similar to the global code.

Why use PHP?

PHP is an Internet tool, running server side, it is a scripting language that may be embedded into web pages. It is usable for processing large data and build a HTML page that display the results. (JavaScript is convenient for dynamic change of HTML pages.)
PHP 5 is a simpler concurrent to Java as an application server and a platform for web applications and web services. It eases the use of XML, MySQL, SQLite, SOAP and many database systems.
PHP is the most used language to build a CMS, content management system.

See also

PHP Editors

Development tools

Scripts and tutorials

Sample code

Displaying chars of a string.

$str = "demo";
$len = strlen($str);
for($i = 0; $i < $len; $i++) 
{ 
  echo $str[$i];
} 

Displaying elements of a list.

$arr = array(1,2,3 );
$arr = array_merge($arr, array( 4,5));
$sub = array_slice(|$arr, 1,3);
foreach($sub $as $num) 
{
  echo $num;
} 
>> should display:  234
Programming languages AspectJ - Basic - C - C++ - C# - Eiffel - Go - Java - JavaScript - JavaFX - Pascal - PHP - Python - Rexx - Ruby - Scala - Scriptol - Tcl - HTML - XML - XAML - XUL - SQL

(c) 2006-2009 Scriptol.com