PHP is a general-purpose scripting language especially suited to web development. PHP stands for Hypertext Preprocessor.
It supports many databases like MySQL, Oracle, Sybase, Solid, PostgreSQL, generic ODBC etc.
PHP file have .php file extension which represent plain-text file that contains the source code written in the PHP.
Basically, PHP is used for created dynamical webpages which means, the some or all of the content of web page is created using database. Although, here are some common uses of PHP :
PEAR is a framework and repository for reusable PHP components. PEAR stands for PHP Extension and Application Repository. It contains all types of PHP code snippets and libraries. It also provides a command line interface to install “packages” automatically.
PHP is partially case sensitive. The variable names are case-sensitive but function names are not. If you define the function name in lowercase and call them in uppercase, it will still work. User-defined functions are not case sensitive but the rest of the language is case-sensitive.
Rasmus Lerdorf is known as father of PHP.
The old name of PHP was Personal Home Page.
The content of Static Website is literally static and doesn’t change in response to user actions. A static website is usually created with HTML and CSS.
Compared to static websites, which are purely informational, a dynamic website is more functional. It allows users to interact with the information that is listed on the page. Of course, that requires utilizing more than just HTML code.
PHP4 doesn't support oops concept and it uses Zend Engine 1.
PHP5 supports oops concept and it uses Zend Engine 2.
To execute a PHP script, use the PHP Command Line Interface (CLI) and specify the file name of the script in the following way:
The PHP parsing engine needs a way to differentiate PHP code from other elements in the page. The mechanism for doing so is known as ‘escaping to PHP’. Escaping a string means to reduce ambiguity in quotes used in that string.
The popularity of PHP is the logical result of its numerous advantages, all of which make it a powerful and effective development tool. Below is the short list of reasons why PHP is a great choice for your web app, which will be subsequently described in more detail.
There are 8 data types in PHP which you can use to construct the variables:
NULL is a special data type which can have only one value. A variable of data type NULL is a variable that has no value assigned to it. It can be assigned as follows:
$var = NULL;
A constant is an identifier (name) for a simple value. The value cannot be changed during the script. Unlike variables, constants are automatically global across the entire script.
define("Message", "Welcome to CodeWolfy!");
The constant() function will return the value of the constant. This is useful when you want to retrieve value of a constant.
<?php define("Message", "Welcome To CodeWolfy!"); echo Message; echo constant("Message"); ?>
PHP has resemble its syntax from Perl and C.
PHP echo output one or more string. It is a language construct not a function. So the use of parentheses is not required. But if you want to pass more than one parameter to echo, the use of parentheses is required.
echo "Welcome to Codewolfy";
Print is language construct in PHP. Which print one string into output. Following is example of Print :
print "Welcome to CodeWolfy!";
Echo can output one or more string but print can only output one string and always returns 1.
Echo is faster than print because it does not return any value.
In PHP, Constants can be defined in two ways :
PHP magic constants are predefined constants, which change based on their use. They start with a double underscore (__) and end with a double underscore (__). Like __LINE__
<?php echo "<h3>Example for __LINE__</h3>"; echo "You are at line number " . __LINE__ . "<br><br>"; //It will print "You are at line number 3" ?>
There is three type of loops in PHP :