Sunteți pe pagina 1din 15

Features of PHP

1.
2.
3.

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


PDF files
Flash movies
Compression
Download and upload
XML support

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


<html>
<head>
<title>PHP Test</title>
</head>
<body>

<?php
echo "<p>Hello World</p>";
echo phpinfo();
?>
</body>
</html>
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 =
2
+
2;
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 casesensitive.
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:
boolean
integer
float
string
Two compound types
array
object
Two special types:
resource
NULL

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.
e.g. $int_var=15;
$str=string1;

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);
?>
o/p :
float(3.1)
bool(true)
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
is_integer
is_float
is_numeric
is_string
is_scalar
is_object
is_array
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.
settype($var, "integer");

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.
error_reporting(E_ALL);
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,


$flag=True;
To define string variable,
$str=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,
define("MAXSIZE", 100);

Operators
Arithmetic : +,-,/,%,*
String . , .=
Assignment operators for all above operators. +=, -= etc , ++ , - Comparision
== , != , <> , > , >= , < , <= , ===
=== returns true if its two operands are having the same value, and
they are of the same type.
e.g.
$a=15;
$b=15;
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.
<?php
$output = `ls`;
echo "<pre>$output</pre>";
?>

Control Structures
if,else,elseif
while,for , do..while , for , foreach , break , continue , switch
$i=1;
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
default :
print "i equals -1";
}
comments .
# , // , /* */

S-ar putea să vă placă și