Wiki

edit

PHP

PHP is a reflective programming language originally designed for producing dynamic web pages. PHP is used mainly in server-side scripting, but can be used from a command line interface or in standalone graphical applications. Textual User Interfaces can also be created using ncurses. PHP is a recursive acronym for "PHP: Hypertext Preprocessor".

Usage

PHP generally runs on a web server, taking PHP code as its input and creating Web pages as output. However, it can also be used for command-line scripting and client-side GUI applications. PHP can be deployed on most web servers and on almost every operating system and platform free of charge. The PHP Group also provides the complete source code for users to build, customize and extend for their own use.

PHP primarily acts as a filter. The PHP program takes input from a file or stream containing text and special PHP instructions and outputs another stream of data for display.

From PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor. PHP 5 uses the Zend Engine II.

Syntax

The usual Hello World code example for PHP is:

Quote <?php echo ‘Hello, World!’; ?>

PHP only parses code within its delimiters, such as <?php ?>. Anything outside its delimiters is sent directly to the output and not parsed by PHP. The example above is equivalent to the following text (and indeed is converted into this form):

Quote Hello, World!

The primary use of this is to allow PHP statements to be embedded within HTML documents, for example:

Quote <html>

<head>
<title><?php echo $page_title;?></title>
</head>
<body>
Hello
</body>

</html>


Variables are prefixed with a dollar symbol and a type does not need to be specified in advance. Unlike function and class names, variable names are case sensitive. Both double-quoted ("") and heredoc strings allow the ability to embed the variable’s value into the string.

PHP treats new lines as whitespace, in the manner of a free-form language (except when inside string quotes). Statements are terminated by a semicolon, except in a few special cases.

PHP has three types of comment syntax: /* */ which serves as block comments, and // as well as # which is used for inline comments.

It should be noted that many examples use the print function instead of the echo function; the two are practically identical, and one may decide which one to use based on his personal preference.

Variables

In PHP, every variable should start with a '$' like we already told before, to assign a new variable, just put something like this in your syntax:

Quote
<?php
#You can see a sample variable below
$variable = 100;
#You can also assign strings to variables
$variable2 = "hi";
#Below we're going to show these variables
echo $variable;
echo $variable2;
?>


It's also possible to show more two variables at the same time, you have to use a dot between variables in the echo command to show them both.

Quote
<?php
$variable = "I am a";
$variable2 = " PHP Programmer.";
#As you can see below, you have to add a dot between two variables to show them both.
echo $variable.$variable2
?>


More about it

Here is the official documentation. It is very useful to learn more about any function.
To go directly on any function page, go to :
Quote http://www.php.net/your_function
For example, to learn more about the function "Print", go to http://www.php.net/print.


Date and Time of posting: 08/05/03 13:23:58