Tuesday, May 3, 2011

Understanding of Php Coding – By Awadhesh


PHP stands for Hypertext Preprocessor. It is a server-side scripting language, like ASP. These scripts are executed on the server. PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.). PHP is an open source software
PHP files can contain text, HTML tags and scripts. PHP files have a file extension of ".php", ".php3", or ".phtml"
PHP runs on different platforms (Windows, Linux, Unix, etc).

Basic PHP Syntax
A PHP scripting block always starts with . A PHP scripting block can be placed anywhere in the document.
On servers with shorthand support enabled you can start a scripting block with .
For maximum compatibility, we recommend that you use the standard form (Below, we have an example of a simple PHP script which sends the text "Hello World" to the browser:

Each code line in PHP must end with a semicolon.

Why do use $ in Php
$ sign is Exclusively use in Php. It instructs to Php Engine That the code inserted with $ sign is Variable.

Variables in PHP
Variables are used for storing values, like text strings, numbers or arrays.
When a variable is declared, it can be used over and over again in your script.
All variables in PHP start with a $ sign symbol.
The correct way of declaring a variable in PHP:
$var_name = value;
Let's try creating a variable containing a string, and a variable containing a number

Naming Rules for Variables
• A variable name must start with a letter or an underscore "_"
• A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
• A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString)

String Variables in PHP
String variables are used for values that contain characters.
Below, the PHP script assigns the text "Hello World" to a string variable called $txt:

The Concatenation Operator
The concatenation operator (.) is used to put two string values together.
To concatenate two string variables together, use the concatenation operator

If we look at the code above you see that we used the concatenation operator two times. This is because we had to insert a third string (a space character), to separate the two strings.
The strlen() function
The strlen() function is used to return the length of a string.

The strpos() function
The strpos() function is used to search for a character/text within a string.
If a match is found, this function will return the character position of the first match. If no match is found, it will return FALSE.

The position of the string "world" in the example above is 6. The reason that it is 6 (and not 7), is that the first character position in the string is 0, and not 1.

To be Continued

No comments:

Post a Comment