Date post: | 19-Nov-2014 |
Category: |
Technology |
Upload: | hainirmalraj |
View: | 2,966 times |
Download: | 1 times |
PHP
Definition:Definition: PHP stands for Personal Home Page. The PHP
Hypertext Preprocessor allows web developers to create dynamic content that interacts with databases. PHP applications are normally found on Linux servers and in conjunction with MySQL databases. It provides those servers with functionality similar to that provided to the Windows platform by Active Server Pages technology.
PHP statements must be inside of PHP tags to be processed by the PHP interpreter. Each PHP statement must end with a semi-colon, which tells the PHP interpreter that the statement is complete. If a semi-colon does not appear at the end of a line, the interpreter will assume that the statement continues onto the next line.
The PHP interpreter condenses all sequential whitespace in PHP scripts to a single whitespace. This convenient feature allows PHP developers to structure their code in a readable format without being concerned about the effects of line breaks and tabs.
COMMENTSCOMMENTS
PHP has two forms of comments:
* Single-line comments begin with a double slash (//).
* Multi-line comments begin with "/*" and end with "*/".
SYNTAXSYNTAX
// This is a single-line comment/*
This is a multi-line comment.*/
PHP FUNCTIONPHP FUNCTION
There are literally hundreds of built-in PHP functions that do everything from returning the current date
and time on the server to pulling data out of a database. A function might take zero arguments (e.g, phpinfo(), which returns information on the
PHP environment) or it might take several arguments
SYNTAXSYNTAX
The syntax for calling a function is straightforward:
Syntax:
function_name(arguments);function_name(arguments);
SAMPLE CODESAMPLE CODE
PhpBasics/Demos/PhpInfo.php<html><html><head><head><title>PHPINFO</title><title>PHPINFO</title></head></head><body><body><?php<?php//Output information on the PHP environment//Output information on the PHP environmentphpinfo();phpinfo();?>?></body></body></html></html>
PHP OPERATORPHP OPERATOR
Mathematical Operators Operator Name.
Example: Addition
+ $a + $b
Subtraction -
$a - $b
Multiplication
*$a * $b
Division
/
$a / $b
Modulus
%
$a % $b
String Operators Operator Name
Example
.Concatenation
$a . $b
'Hello' . ' world!'
Assignment Operators Operator Name Example
=
Assignment
$a = 1;
$c = 'Hello' . ' world!';
+=
-=
*=
/=
%=
.=
Combination Assignment
$a += 1;
$a -= 1;
$a *= 2;
$a /= 2;
$a %= 2;
$a .= ' world!';
Increment By One
++
$a++;
++$a;
Decrement By One
--
$a--;
--$a;
Other Operators Operator Name Example
Ternary
?:
$foo = ($age >= 18) ? 'adult' : 'child';
Error Suppression
@
Creating Dynamic Pages
$a = @(1/0);
SAMPLE CODE:<html><html><head><head>
<title>Hello World!</title><title>Hello World!</title></head></head><body><body><?php<?php
//Write out Hello World!//Write out Hello World!echo 'Hello World!';echo 'Hello World!';
?>?></body></body></html></html>
PHP.NETPHP.NET
BASIC PHP SYNTAXBASIC PHP SYNTAX
PHP Tags: PHP code must be contained in special tags so
that the PHP interpreter can identify it. Depending on the PHP configuration, these tags can take
several forms:<?php?php
PHP CODE GOES IN HEREPHP CODE GOES IN HERE?> ?>
This is the most commonly used (and recommended) form. It is known as the XML style, because it can be used inside of an XML document without causing the
document to become poorly formed.
<script language="php"><script language="php">
PHP CODE GOES IN HEREPHP CODE GOES IN HERE
</script> </script>
Less is more. The shortest and easiest way to deal with the xml tag problem assuming short tags is
enabled and you don't care to listen to people who want you to always use the full php tag is this:
<<??>?xml version="1.0" encoding="utf-8"?><<??>?xml version="1.0" encoding="utf-8"?>
you also can use this kind of syntax:
<?php if( condition ): ?><?php if( condition ): ?>
<?php else: ?><?php else: ?>
<?php endif; ?><?php endif; ?>
<?PHP CODE GOES HERE
?>
"Short" tags.
<%PHP CODE GOES HERE
%>
HTML STYLE TAGHTML STYLE TAG