Professional Documents
Culture Documents
12/9/2013
PHP : Rasmus Lerdorf in 1994 (c pht trin pht sinh cc form ng nhp s
Services, SQLite
Phin bn mi nht ca PHP l version PHP 5.4.11 || 5.3.21 || 5.5.0
(www.php.net)
Software
Platform
Free
Free (Linux)
Development Tools
10
http://www.php.net/usage.php
12/9/2013
11
12
www.example.com
Webserver
Apache
or IIS
Internet
or Intranet
7
ServerSide Script
Parser
(PHP, ASP, ..)
Database
Server
Disk
driver
12/9/2013
13
14
15
16
17
18
<?
?>
<?php
?>
<script language="php">
<script>
19
20
21
22
23
24
Cch 1 (automatic)
$var = "100" + 15;
$var = "100" + 15.0;
$var = 39 . " Steps";
$var
(int)$var
(bool)$var
(string)$var
null
false
true
false
6 feet
true
foo
true
25
26
abs
ceil
Floor
round
pow
sqrt
log
log10
decbin
bindec
dechex
hexdec
srand(seed)
rand
rand(min, max)
V d
$var = "test";
if (isset($var))
echo "Variable is Set";
if (empty($var))
echo "Variable is Empty";
27
28
<?
$tax = 0.075;
printf('The tax costs $%.2f', $tax);
printf
str_pad
strlen
trim
str_replace
substr
strtolower
strtoupper
strcasecmp
$zip = '6520';
printf("ZIP is %05d, $zip);
$min = -40; $max = 40;
printf("The computer can operate between %+d and %+d
degrees Celsius.", $min, $max);
?>
29
30
31
32
33
34
35
36
37
38
V d:
if (condition)
{
statement[s] if true
}
else (condition)
{
statement[s] if false
}
switch (expression)
$menu = 3;
switch ($menu){
case 1:
echo "You picked
break;
case 2:
echo "You picked
break;
case 3:
echo "You picked
case 4:
echo "You picked
break;
default:
echo "You picked
option";
}
$x = 5;
case label :
if ($x < 4)
statementlist
break;
else
case label :
statementlist
break;
...
default :
statementlist
}
one";
two";
three";
four";
another
39
40
while (expression)
{
statements
}
V d:
$i = 1; $j = 9;
while ($i <= 10) {
$temp = $i * $j;
print $j * $i = $temp<br>";
do
{
$i++;
statements
}while (expression);
41
42
43
44
<?php
function doublevalue($var=5)
{
global $temp;
$temp = $var * 2;
}
$temp = 5;
doublevalue();
echo "\$temp is: $temp";
?>
45
<?php
function doublevalue(
{
$var = $var * 2;
}
$var)
46
// functions.inc
// index.php
<?php
<html>
function bold($string)
<head>
<title>Simple Function
{
echo "<b>" . $string .
$variable = 5;
doublevalue($variable);
echo "\$variable is: $variable";
?>
Call</title>
"</b>\n";
</head>
<body bgcolor="#ffffff">
?>
<?
include
"functions.inc";
require
"functions.inc";
bold("this is bold");
$myString = "this is bold";
bold($myString);
?>
</body></html>
47
48
function method_name()
{
$this->attribute = ;
}
$a = new class_name();
49
class Counter
{
var $count = 0;
var $startPoint = 0;
function increment(
$this->count++;
}
}
$aCounter = new Counter;
$aCounter->increment( );
echo $aCounter->count; // prints 1
$aCounter->count = 101;
12/9/2013
50