PHP stands for Hypertext Preprocessor“. It is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
It is an interpreted language.
There are three main fields where PHP scripts are used.
Server side scripting
Command line scripting.
Writing client-side GUI applications.For this PHP-GTK is used. PHP-GTK is an extension for the PHP programming language that implements language bindings for GTK+. It provides an object-oriented interface to GTK+ classes and functions and greatly simplifies writing client-side cross-platform GUI applications.
PHP can be used on all major operating systems, including Linux, many Unix variants, Microsoft Windows, Mac OS X etc.
PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server and many others.
You also have the choice of using procedural programming or object oriented programming, or a mixture of them.
PHP does more than just generating dynamic web-pages. PHP's abilities includes:
Generating images dynamically
Download and upload
PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others.
You can also open raw network sockets and interact using any other protocol.
PHP has support for the WDDX complex data exchange between virtually all Web programming languages. (Support for web services)
PHP has support for instantiation of Java objects and using them transparently as PHP objects. You can also use CORBA extension to access remote objects.
e.g. You can use java classes in php.
A sample PHP script
<head> <title>PHP Test</title>
echo "<p>Hello World</p>";
A call to the phpinfo() function returns a lot of useful information about your system and setup such as available predefined variables, loaded PHP modules, and configuration settings.
php syntaxes are similar to C.
php is whitespace insensitive.
e.g. $four =
php is sometimes case insensitive. i.e. All variables are case sensitive.
Basics of variable
Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.
PHP is also context-sensitive like perl.
A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
PHP provides 8 primitive data-types.
Four scalar types:
Two compound types
Two special types:
PHP,types are associated with values rather than variables. No previous declaration is needed. You can assign value to variable as and when you need it.
If you want to check out the type and value of a certain variable, use var_dump() .
It dumps information about variable.
<?php $b = 3.1; $c = true; var_dump($b, $c); ?>
If you want to get type of a variable, then use gettype().
echo gettype($bool); // prints out "boolean“
echo gettype($str); // prints out "string“
To check type of veriables in condition, separate functions are there for each type.
basic syntax is is_type(variable)
some of it are
It returns true if variable will be of that specific type. Otherwise it returns false.
If you would like to force a variable to be converted to a certain type, you may either cast the variable or use the settype() function on it. It returns true on success and false on failure.
In php, default error reporting setting allows you to use unassigned variables without errors.
To change this setting you should set error reporting level to E_ALL in your php.ini file.
To check if variable is assigned a value or not, use isset($var) .
PHP variables are global in scope. You can use it throughout your program.
To define boolean variable,
To define string variable,
String can be enclosed in double quotes, single quotes or you can also use heredoc operator.
$str = <<<EOF Example of string spanning multiple lines using heredoc syntax. EOF;
To define constant,
Arithmetic : +,-,/,%,*
String . , .=
Assignment operators for all above operators. +=, -= etc , ++ , --
== , != , <> , > , >= , < , <= , ===
=== returns true if its two operands are having the same value, and they are of the same type.
if( $a === $b)
print “Identical variables”;
PHP supports one execution operator: backquotes (``).
PHP will attempt to execute the contents of the backquotes as a system command; the output will be returned in a variable.