PHP Basic Introduction

PHP stands for PHP Hypertext Preprocessor.

Taken directly from PHP’s home, PHP.net, “PHP is an HTML-embedded scripting language.

Syntax
PHP’s syntax is derived from many languages—predominantly the C language, but Perl has also had a lot of influence on its syntax. With the latest object-oriented additions, more Java-like syntax is creeping in as well. Despite incorporating elements of so many other languages, PHP’s syntax remains simple and easy to understand.

The PHP is a powerful, behind the scenes scripting language that your visitors won’t see!

PHP Tags
Even though it is often used as a pure language, PHP is primarily designed as a text processor (hence its name). To facilitate this role, PHP code can be inserted directly into a text file using a special set of tags; the interpreter will then output any text outside the tags as-is, and execute the code that is between the tags.

The tags available:
Short tage
<?
... code
?>
<?= $variable ?>  Short tage strongly discoureged
Standard tags
<?php
... code
?>  Standard tags

Comments
Another common part of any programming language is comments. It is a good programming practice to comment every function, class, method or property in your code (although youwill likely come across lots of code that is poorly commented—or not at all). Remember—any code that took thought to write will take thought to reread after several days, months or in some cases, years.

As with tags, PHP gives you multiple choices for your comments:
// Single line comment
# Single line comment
/* Multi-line
comment
*/

Both types of single line comments, // and #, can be ended using a newline (\r, \n or \r\n) or by ending the current PHP block using the PHP closing tag—?>.

Code Block
A code block is simply a series of statements enclosed between two braces:

{
// Some comments
f(); // a function call
}

Code blocks are handy for creating groups of script lines that must all be executed under specific circumstances, such as a function call or a conditional statement. Code blocks can be nested.

Language Constructs

Constructs are elements that are built-into the language and, therefore, follow special rules. Perhaps the most common of them is the echo statement, which allows you to write data to the script’s output:

<?php
echo 10; // will output 10
?>

It’s important to understand that echo is not a function and, as such, it does not have a return value. If you need to output data through a function, you can use print() instead:

<?php
echo 10;
print (10);
?>

Another very important construct is die(), which is itself an alias of exit(). It allows you to terminate the script’s output and either output a string or return a numeric status to the process that called the script.

Next Topic

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

1 Comment

  1. avatarjosh

    As s beginner great info to me, thank you…

Leave a Comment

Your email address will not be published. Required fields are marked *