Professional Documents
Culture Documents
Lm vic vi Form
Cc hm lm vic vi MySQL
Lm vic vi File
Cc hm lm vic vi hnh nh
Cc hm trn d liu
Cookies v QueryString
Session
G li
I. Lm quen vi PHP
.1. PHP l g?
.2. Ljch s pht trin ca PHP
.3. L do chn PHP
.4. Zend Engine
.5. Ci dt PHP
.6. Chong trnh PHP du tin
.7. Cc DE cho PHP
I.1. PHP I g?
Theo NetCraft:
Ngi dng gi yu cu ln my ch
PHP cho php ban tch phn HTML code v phn script,
do d c th dc lp gia cng vic pht trin m v thit
k. iu ny va gip lp trnh vin d dng hon va c
th lm cho chong trnh mm do hon trong vic thay di
giao din
Tc d
Tnh kh chuyn
Ci dt Apache
I.5. Ci dt PHP (3)
Macromedia DreamWaver
Nusphere PHPED
Zend Studio
II. PHP Cn bn
.1. Bin, kiu v hng
.2. Ton t v biu thc
.3. Cc cu lnh diu khin
.4. Hm
.5. Lp di tong
.6. Tham chiu (reference)
II.1. Bin, kiu v hng
.1.1. Bin
.1.1.1. Tn bin
.1.1.2. Tham chiu
.1.1.3. Bin dng
.1.1.4. Pham vi (scope) ca bin
.1.2. Kiu
.1.3. Hng
II.1.1.1. Tn bin
<?php
$var = "Bob";
$Var = "Joe";
echo "$var, $Var"; // outputs "Bob, Joe"
$4site = 'not yet'; // invalid; starts with a number
$_4site = 'not yet'; // valid; starts with an underscore
$tyte = 'mansikka'; // valid; '' is (Extended) ASCII 228.
?>
Bin doc k hiu bi k t $
Tn bin phi doc bt du bi 1 ch ci hoc k t gach
chn
Tn bin khng cha cc du v k t cch
II.1.1.2. Tham chiu
Ging ngn ng C, trong PHP ban c th s dung tham chiu
<?php
$quang = "adfsdfasdfa";
echo("<p>$quang</p>");
$q = &$quang;
$q = "quangnp";
echo("<p>$quang</p>");
?>
<?php
$foo = 25;
$bar = &$foo; // This is a valid assignment.
$bar = &(24 * 7);// Invalid references an unnamed exression.
function test() {
return 25;
}
$bar = &test(); // Invalid.
?>
II.1.1.3. Bin dng (Dynamic VariabIe)
PHP l ngn ng thng djch nn ban c th s dung cc bin
c tn cha bit trc (tn bin thay di)
<?php
$a = "quang"; // gia tri cua !ien a la "#uang"
$$a = "np"; // !ien dong $#uang co gia tri la "n"
echo("$a<br>"); // In ra gia tri cua !ien a
echo("$quang<br>"); // In ra gia tri cua !ien #uang
${"quang"} = 13432; // %ian truc tie !ien dong
echo("$quang<br>");
$c = "quang";
${$c} = 1000;
// Mot cach &hac de truy ca den !ien dong #uang
echo("${$c}<br>");
?>
II.1.1.4. Pham vi ca bin
<?php
$a = 1;
include "b.inc";
?>
Pham vi ca bin a c tc dung trong c b.inc
<?php
$a = 1; // glo!al scoe
function Test() {
echo $a; // reference to local scoe varia!le
}
Test();
?>
Bin a ngoi v trong hm Test khc nhau
II.1.1.4. Pham vi ca bin (2)
T kha global
<?php
$a = 1;
$b = 2;
function Sum() {
//a' ! trong ( ngoai ham )um
global $a, $b;
// la giong nhau
$b = $a + $b;
}
Sum();
echo $b;
?>
Hoc s dung c php
<?php
$a = 1;
$b = 2;
function Sum() {
$GLOBALS["b"] =
$GLOBALS["a"] +
$GLOBALS["b"];
}
Sum();
echo $b;
?>
II.1.1.4. Pham vi ca bin (3)
<?php
function Test ()
{
$a = 0;
echo $a;
$a++;
}
Test();
Test();
?>
<?php
function Test ()
{
static $a = 0;
echo $a;
$a++;
}
Test();
Test();
?>
II.1.1.4. Pham vi ca bin (4)
<?php
$foo = 25;
$bar = &$foo; // This is a valid assignment.
function test()
{
global $foo;
return $foo;
}
$bar = &test(); // Invalid.
echo($bar);
?>
II.1.2. Kiu
Cc kiu don
.1.2.1. boolean
.1.2.2. integer
.1.2.3. float
.1.2.4. string
Cc kiu phc
.1.2.5. array
.1.2.6. obect
Cc kiu dc bit
.1.2.7. resource
.1.2.. NULL
II.1.2. Kiu (2)
<?php
$bool = TRUE; // a !oolean
$str = "foo"; // a string
$int = 12; // an integer
echo gettype($bool); // rints out *!oolean*
echo gettype($str); // rints out *string+
// If this is an integer' increment it !y four
if (is_int($int)) {
$int += 4;
}
// If $!ool is a string' rint it out
// ,does not rint out anything-
if (is_string($bool)) {
echo "String: $bool";
}
?>
Ban c th p kiu bng hm settype()
II.1.2.1. Kiu booIean
<?php
// .. is an oerator /hich test
// e#uality and returns a !oolean
$q = (1==1);
echo("$q<br>");
$q = (1=="1");
echo("$q<br>");
// this is not necessary...
if ($show_separators == TRUE) {
echo "<hr>\n";
}
// ...!ecause you can simly tye
if ($show_separators) {
echo "<hr>\n";
}
?>
II.1.2.2. Kiu integer
<?php
$a = 1234; # decimal num!er
$a = -123; # a negative num!er
$a = 0123; # octal num!er ,e#uivalent to 01 decimal-
$a = 0x1A; # hexadecimal num!er ,e#uivalent to 23
decimal-
?>
<?php
$a=10000000;
var_dump($a); echo("<br>");
$a=100000000;
var_dump($a); echo("<br>");
$a=1000000000;
var_dump($a); echo("<br>");
$a=10000000000;
var_dump($a); echo("<br>");
?>
II.1.2.3. Kiu fIoat
<?php
$a = 1.234;
$b = 1.2e3;
$c = 7E-10;
?>
<?php
$foo = 1 + "10.5"; // $foo is float ,44.5-
$foo = 1 + "-1.3e3"; // $foo is float ,64277-
$foo = 1 + "bob-1.3e3"; // $foo is integer ,4-
$foo = 1 + "bob3"; // $foo is integer ,4-
$foo = 1 + "10 Small Pigs"; // $foo is integer ,44-
$foo = 4 + "10.2 Little Piggies"; // $foo is float ,48.2-
$foo = "10.0 pigs " + 1; // $foo is float ,44-
$foo = "10.0 pigs " + 1.0; // $foo is float ,44-
?>
II.1.2.4. Kiu string
Heredoc
Khai bo
<?php
$ar = array(3,4,5,6,3,2);
echo var_dump($ar), "<br>";
$ar = array(5=>10, 20, 30, "q"=>40);
echo var_dump($ar), "<br>";
$ar = array(5=>10, 6=>20, 7=>30, "q"=>40);
echo var_dump($ar), "<br>";
$ar = array("a"=>10, 20, 30, 40);
echo var_dump($ar), "<br>";
$ar = array("a"=>array(1,2,3,4,5), 20, 30, 40);
echo var_dump($ar);
?>
II.1.2.5. Kiu Array (3)
S dung array
<?php
$arr = array(5 => 1, 12 => 2);
$arr[] = 56; // This is the same as $arr:41; . 53<
// at this oint of the scrit
$arr["x"] = 42; // This adds a ne/ element to
// the array /ith &ey *x*
unset($arr[5]); // This removes the element from the array
unset($arr); // This deletes the /hole array
?>
<?php
$handle = opendir(".");
var_dump($handle);
while($file=readdir($handle)) {
$files[] = $file;
}
var_dump($files);
?>
II.1.2.6. Kiu Object
<?php
class Xeco {
var $sobanh;
function BaoNhieuBanh() {
echo($this->sobanh);
}
};
$xe = new Xeco();
$xe->sobanh = 4;
$xe->BaoNhieuBanh();
?>
II.1.3. Hng
jnh ngha hng bng cch s dung hm define()
Pham vi ca hng l ton cuc (global)
Chi c cc dang d liu don gin (boolean, interger, float, string)
Nu tn hng cha doc djnh ngha, PHP gi thit rng ban dang s dung
1 hng cha gi trj l 1 string (chnh l tn ca hng d)
xc djnh mt hng d doc djnh ngha hay cha, ban c th s dung
hm defined
<?php
define("CONSTANT", "Hello world.");
echo CONSTANT; // oututs *Hello /orld.*
echo Constant; // oututs *Constant* and issues a notice.
echo defined("Constant");
echo defined("CONSTANT");
?>
II.1.3. Hng (2)
Tham chiu cho php ban s dung 1 bin vi nhiu tn khc nhau
i vi di tong, nn s dung php gn tham chiu khi dng ton t new d trnh php
gn tao ra thm 1 phin bn ca di tong
thay di gi trj ca tham s truyn vo trong hm, ban c th s dung tham chiu
<?php
$a = &$b;
$b = 100;
var_dump($a);
class AClass {};
$c = new AClass();
$d =& new AClass();
function increment(&$num) {
$num++;
}
$a = 10;
increment($a);
var_dump($a);
?>
II.6.2. Cc trung hp ko s dng
tham chiu
<?php
function foo(&$var)
{
$var =& $GLOBALS["quang"];
var_dump($var);
}
$quang = "Nguyen Phu Quang";
$var = 100;
foo($var);
var_dump($var);
?>
II.6.3. Truyn tham chiu
Bin foo(a)
Tham chiu tr v t hm
<?php
function foo(&$num) {
$num++;
}
function &bar() {
global $a;
return $a;
}
$a=10;
foo($a); var_dump($a);
foo(bar()); var_dump($a);
foo($a = 5); var_dump($a);
foo(5);
?>
II.6.4. Tr v tham chiu
<?php
function &bar() {
global $a;
return $a;
}
$a = 10;
$c = bar();
$c++;
var_dump($a);
var_dump($c);
$b =& bar();
$b++;
var_dump($a);
var_dump($b);
?>
II.6.5. Unset tham chiu
<?php
$a = &$b;
$b = 100;
unset($a);
var_dump($a);
var_dump($b);
unset($b);
var_dump($a);
var_dump($b);
?>
III. Lm vic vi Form
.1. Cc bin SuperGlobal
.2. Bin SERER
.3. Ly thng tin t form
.4. Kt hop m HTML v PHP trong 1 trang
.5. S dung Hidden field d lu trang thi
.6. Redirect
.7. Form Upload file
III.1. Cc bin SuperGIobaI
Mng FLE
image/gif
MIME type of uploaded file
(where given by client)
$_FILES['fupload']['type']
UPLOAD_ERR_FOR
M_SIE
An error code
corresponding to a PHP
constant
$_FILES['fupload']['e!!o!']
68! "i#e (in bytes) of uploaded
file
$_FILES['fupload']['"i#e']
/tmp/p$p!Df%&
Path to te$porary file
$_FILES['fupload']['tmp_'a
me']
te"t(gif
%a$e of uploaded file
$ FILES['fupload'][''ame']
E&a$ple 'ontains Ele$ent
(ile was not uploaded
* UPLOAD_ERR_&O_FILE
(ile only partially uploaded
+ UPLOAD_ERR_PAR,IAL
(ile si#e e&ceeds li$it set in hidden
ele$ent na$ed MA-_FILE_SIE
. UPLOAD_ERR_FORM_SI
E
(ile si#e e&ceeds p$p(i'i li$it set in
upload_ma/_file"i#e
0 UPLOAD_ERR_I&I_SIE
%o proble$
1 UPLOAD_ERR_O2
E&planation
)alu
e 'onstant %a$e
III.7. Form UpIoad fiIe (3)
<?php
if ($_REQUEST["submit"]=="upload!") {
echo $_!"ES["#upload"]["$%%o%"]& "\n"'
echo $_!"ES["#upload"]["si($"]& "\n"'
echo $_!"ES["#upload"][")am$"]& "\n"'
echo $_!"ES["#upload"]["tmp_)am$"]& "\n"'
if ($_!"ES["#upload"]["$%%o%"]==0) {
$sou%*$ = $_!"ES["#upload"]["tmp_)am$"]'
$d$st = $_!"ES["#upload"][")am$"]'
mo+$_upload$d_#il$($sou%*$& $d$st)'
,
,
?-
<#o%m $)*t.p$="multipa%t/#o%m0data" m$thod="post"-
<p-
<i)put t.p$="hidd$)" )am$="123_!"E_S!4E" +alu$="567866" /-
<i)put t.p$="#il$" )am$="#upload" /-<b%/-
<i)put t.p$="submit" +alu$="upload!" )am$="submit" /-
</p-
</#o%m-
IV. Lm vic vi fiIe
.1. S dung include()
.2. S dung includeonce() v includepath
cho cc d n ln
.3. Kim tra file
.4. c, ghi file
.5. Lm vic vi th muc
IV.1. S dng incIude()
Lnh include() cho php ban phi hop gia cc file trong mt
PHP proect, ko ging nh c php include ca ngn ng C,
lnh ny khng chn m lnh vo file m thc thi file php ging
nh c php gi hm
<!00il$59php0-
<?php
echo "This is #%om #il$ 5\n"'
?-
<!00il$79php 0-
<?php
echo "This is #%om #il$ 7\n"'
include("#il$59php")'
include("#il$:9php")'
echo "This is #%om #il$ 7\n"'
?-
IV.1. S dng incIude() (3)
<!00il$559php00-
<?php
return 4 ; 4'
?-
<!00il$579php00-
<?php
echo "This is #%om #il$ 57\n"'
$%$t<al = include("#il$559php")'
echo "R$tu%) +alu$ #%om #il$ 55= \$%$t<al=
$retVal\n"'
echo "This is #%om #il$ 57\n"'
?-
IV.1. S dng incIude() (4)
<!--File22.php-->
<?php
if ($j==null) $j=10; else $j++;
return $i+$j;
?>
<!--File21.php-->
<?php
for ($i=0; $i<10; $i++) {
echo include("File22.php"), "\n";
}
?>
IV.2. S dng incIude_once() v
incIude_path cho cc d n In
<?php
include_once("a.php"); // this /ill include a.h
include_once("A.php"); // this /ill include a.h
again on Bindo/sC
?>
IV.2. S dng incIude_once() v
incIude_path cho cc d n In (2)
<?php
var_dump(get_include_path());
set_include_path('/inc'); // Bor&s as of PHP 8.1.A
var_dump(get_include_path());
restore_include_path();
var_dump(get_include_path());
?>
<?php
var_dump(ini_get("include_path"));
ini_set("include_path", "/inc"); // Bor&s in all PHP versions
var_dump(ini_get("include_path"));
ini_restore("include_path");
var_dump(ini_get("include_path"));
?>
IV.3. Kim tra fiIe
<?php
function outputFileTestInfo( $file ) {
if ( ! file_exists( $file ) ) {
print "$file does not exist<br/>";
return;
}
print "$file is ".(is_file( $file )?"":"not ")."a file<br/>\n";
print "$file is ".(is_dir( $file )?"":"not ")."a directory<br/>\n";
print "$file is ".(is_readable( $file )?"":"not ")."readable<br/>\n";
print "$file is ".(is_writable( $file )?"":"not ")."writable<br/>\n";
print "$file is ".( filesize($file))." bytes<br/>\n";
print "$file was accessed on "
.date( "D d M Y g:i A", fileatime( $file ) )."<br/>\n";
print "$file was modified on "
.date( "D d M Y g:i A", filemtime( $file ) )."<br/>\n";
print "$file was changed on"
.date( "D d M Y g:i A", filectime( $file ) )."<br/>\n";
}
outputFileTestInfo("c:\\windows\\system32\\cmd.exe");
?>
IV.4. c, ghi fiIe
fopen($filename, $mode);
fwrite($handle, $string);
fread($handle, $length);
fgets($handle);
sprintf($format);
fscanf($handle, $format);
fseek($handle, $offset);
fclose($handle);
file_get_contents($filename);
IV.4. c, ghi fiIe (2)
<?php
$var1 = 10;
$var2 = "This is a String";
$var3 = true;
$f = fopen("test.txt", "wt");
fwrite($f, "$var1 $var2 $var3\n");
fwrite($f, "$var1\n$var2\n$var3\n");
fclose($f);
echo "Read line by line......\n";
$f = fopen("test.txt", "rt");
while (!feof($f)) {
$line = fgets($f);
echo "$line";
}
fclose($f);
echo "Read all file by fread......\n";
$f = fopen("test.txt", "rb");
$myfile = fread($f, filesize("test.txt"));
echo $myfile;
fclose($f);
echo "Read all file......\n";
$myfile = file_get_contents("test.txt");
echo($myfile);
?>
IV.4. c, ghi fiIe (3)
<?php
$+a%5=10'
$+a%7=100'
$+a%:=5669:8:8'
$+a%8="T$st st%i)>"'
$#=#op$)("t$st9t?t"& "@t")'
#@%it$($#& sp%i)t#("Ad A569:# A569:l#\n\r"& $+a%5& $+a%7& $+a%:))'
#@%it$($#& sp%i)t#("As"& $+a%8))'
#*los$($#)'
$#=#op$)("t$st9t?t"& "%t")'
if (list($+5& $+7& $+:& $+8) = #s*a)#($#& "Ad A# Al#\n\rAs")) {
+a%_dump($+5)'
+a%_dump($+7)'
+a%_dump($+:)'
+a%_dump($+8)'
,
$+8 = #>$ts($#)'
+a%_dump($+8)'
#*los$($#)'
?-
IV.4. c, ghi fiIe (4)
<?php
class 2Blass {
,'
$ob5 =C new 2Blass()'
$ob50-a = 10'
$ob50-b = 566967:'
$ob50-* = "T$st St%i)>"'
+a%_dump($ob5)'
$# = #op$)("t$st9t?t"& "@b")'
#@%it$($#& s$%iali($($ob5))'
#*los$($#)'
$# = #op$)("t$st9t?t"& "%b")'
$ob7 = u)s$%iali($(#>$ts($#))'
#*los$($#)'
+a%_dump($ob7)'
?-
IV.5. Lm vic vi thu mc
<?php
$di%=op$)di%("*=\\@i)do@s")'
while ($#il$=%$addi%($di%)) {
echo "$file\n"'
,
*los$di%($di%)'
?-
V. PHP & CSDL
.1. S dung PHP d kt ni vi CSDL
.2. PEAR DB
.3. Cc chc nng nng cao vi PEAR DB
V.1. S dng PHP d kt ni vi
CSDL
Ci dt th vin PEAR
Ci dt PHP
Chay go-pear.bat
includepath=.C:/php/pear
extensiondir=c:/php/ext
Copy \Mysql\bin\libMysql.dll dn
c:\windows\system32
type://username:passwordprotocolhost
spec/database
du:
mysql:///webdb mysql://localhost/webdb
mysql://bondviewlocalhost/webdb
mysql://bondviewtcplocalhost/webdb
mysql://bondview:007localhost/webdb
FrontBase Fbsql
Informix Ifx
SyBase Sybase
ODBC Odbc
Oracle 7/8/8i oci8
Microsoft SQL Server Mssql
Mini SQL Msql
InterBase Ibase
PostgreSQL Pgsql
MySQL Mysql
*atabase +ype
V.2.2. Kt ni vi co s d Iiu
$db = EF==*o))$*t($datasou%*$)'
if (EF==isE%%o%($db)) {
die($db0->$t1$ssa>$( ))'
,
V.2.4. Thc thi query
$db = EF==*o))$*t($datasou%*$)'
$%$sult = $db0-Hu$%.(sHl)'
if (EF==is$%%o%($%$sult)) {
die($%$sult0->$t1$ssa>$())'
,
V.2.5. Ly kt qu t query
<?php
$db = DB::connect($datasource);
$result = $db->query(sql);
while ($row = $result->fetchRow( )) {
if (DB::isError($row)) {
die($row->getMessage( ));
}
// do something /ith the ro/
}
?>
V.2.5. Ly kt qu t query (2)
mode:
<?php
require("DB.php");
$db =
DB::connect("mysql://root:root@localhost/d
hxd");
$table = $db->query("select * from sv");
$row = $table->fetchRow();
unset($row);
$table->free();
$db->disconnect();
?>
V.3. Cc chc nng nng cao vi
PEAR DB
.3.1. Query template
.3.2. Prepare/Execute
.3.3. Cc hm tin ch
.3.4. Cc thng tin tr v t query()
.3.5. Metadata
V.3.1. Query tempIate
Trong trng hop ny, PHP cung cp 1 cng cu hoat dng cho
php truyn tham s trong cu lnh SQL ging nh lnh printf,
trong d s dung cc k hiu
<?php
require("EF9php")'
$db = EF==*o))$*t("m.sHl=//%oot=%ootIlo*alhost/dh?d")'
$%o@ = array("J>u.$) <a)"& "2")'
$db0-Hu$%.("!JSERT !JTK s+ (hod$m& t$)) <2"UES(?&?)"& $%o@)'
?-
V.3.2. Prepare/Execute
Khi ban thc hin nhiu cu lnh ging nhau, cch tt nht l djch cu lnh SQL trc khi
thc hin bng phong thc prepare()
Sau khi djch SQL, ban c th thc hin cu lnh SQL bng cch dng 2 lnh sau:
<?php
require("EF9php")'
$db = EF==*o))$*t("m.sHl=//%oot=%ootIlo*alhost/dh?d")'
$*ompli$d = $db0-p%$pa%$("!JSERT !JTK s+ (hod$m& t$))
<2"UES(?&?)")'
$%o@s=array( array("J>u.$) <a)"& "2")&
array("J>u.$) <a)"& "F")&
array("J>u.$) <a)"& "B")&
array("J>u.$) <a)"& "E") )'
foreach ($%o@s as $%o@) {
$db0-$?$*ut$($*ompli$d& $%o@)'
,
$db0-$?$*ut$1ultipl$($*ompli$d& $%o@s)'
?-
V.3.3. Cc hm tin ch
Thng th cc hm ghi thng tin ra browser. Tuy nhin c nhiu trng hop chng
ta khng mun nh vy.
Ban c th s dung vng dm ra (output buffer) d cc lnh ghi thng tin ghi d liu
ln d
<?php
ob_sta%t()'
phpi)#o()'
$phpi)#o = ob_>$t_*o)t$)ts()'
ob_$)d_*l$a)()'
if (st%pos($phpi)#o& "modul$_pd#") === FALSE) {
echo "Lou do )ot ha+$ ME suppo%t i) .ou% MNM& so%%.9"'
, else {
echo "Bo)>%atulatio)s& .ou ha+$ ME suppo%t!"'
,
?-
VI.4. Qun I Ii
.4.1. Thng bo li
.4.2. Giu li
.4.3. Pht sinh li
.4.4. Hm x l li
.4.5. Log li
VI.4.1. Thng bo Ii
<?php
i)i_s$t("t%a*O_$%%o%s"& "5")'
$+alu$ = 2/0'
$+alu$ = I(2/0)'
echo "$php_errormsg"'
i)i_%$sto%$("t%a*O_$%%o%s")'
?-
<?php
$%%o%_%$po%ti)>(0)'
i)i_s$t("t%a*O_$%%o%s"& "5")'
$+alu$ = 2/0'
echo "$php_errormsg"'
i)i_%$sto%$("t%a*O_$%%o%s")'
?-
VI.4.3. Pht sinh Ii
triggererror(message , type)
<?php
function di+id$%($a& $b) {
if($b == 0) {
t%i>>$%_$%%o%(G$b *a))ot b$ 6G& _USER_ERRKR)'
,
return($a / $b)'
,
?-
VI.4.4. Hm x I Ii
<?php
function m._ha)dl$%($$%%o%& $$%%o%st%i)>&
$#il$)am$& $li)$& $s.mbol)
{
echo "$errorP$errorstringP$filenameP$line\n"'
,
s$t_$%%o%_ha)dl$%(Gm._ha)dl$%G)'
echo 4/0'
$# = #il$("li)hti)h")'
?-
VI.4.5. Log Ii
VI.5. Ti uu ha
VII. Hnh nh
.1. u cu phn mm
.2. Tao v v nh
.3. Text
.4. Co dn nh
VII.1. Yu cu phn mm
<?php
$im = ima>$*%$at$(30& 30)'
$%$d = ima>$*olo%allo*at$($im& 0xff& 0x00& 0x00)'
$blu$ = ima>$*olo%allo*at$($im& 0x00&0x00&0xff)'
$bla*O = ima>$*olo%allo*at$($im& 0x00& 0x00& 0x00)'
ima>$#ill$d%$*ta)>l$($im& 0& 0& 29& 29& $bla*O)'
ima>$#ill$d%$*ta)>l$($im& 0&0&15&15&$%$d)'
ima>$#ill$d%$*ta)>l$($im& 15&15&29&29&$blu$)'
ima>$Qp$>($im& "*=/t$st9Qp>"& 100)'
?-
<html-
Ea. *u)> la *a%o= <im> s%* = "*=/t$st9Qp>"/-
</html-
VII.2. Tao v v nh (2)
Cc hm thng s dung
mageSetPixel(image, x, y, color)
mageFill(image, x, y, color)
<?php
$im = ima>$*%$at$(100&100)'
$@hit$ = ima>$*olo%allo*at$($im& 0xff& 0xff& 0xff)'
$%$d = ima>$*olo%allo*at$($im& 0xff& 0x00& 0x00)'
ima>$st%i)>($im& 1& 0& 0& "NUBE"& $%$d)'
ima>$st%i)>($im& 2& 0& 10& "NUBE"& $%$d)'
ima>$st%i)>($im& 3& 0& 20& "NUBE"& $%$d)'
ima>$st%i)>($im& 4& 0& 30& "NUBE"& $%$d)'
ima>$st%i)>($im& 5& 0& 45& "NUBE"& $%$d)'
ima>$st%i)>up($im& 5& 50& 99& "U)i+$%sit."& $%$d)'
ima>$>i#($im)'
?-
VII.3. V Text (2)
<?php
$im = imagecreate(100,100);
$white = imagecolorallocate($im, 0xff, 0xff, 0xff);
$red = imagecolorallocate($im, 0xff, 0x00, 0x00);
$blue = imagecolorallocate($im, 0x00, 0x00, 0xff);
imagettftext($im, 8, 30, 10, 100, $red,
"Times", "HUCE - 46pm1");
imagettftext($im, 10, -30, 10, 10,$blue,
"Arialni","HUCE- 46pm1");
imagegif($im);
?>
VII.4. Co dn nh
<?php
$im = imagecreate(100,100);
$white = imagecolorallocate($im, 0xff, 0xff, 0xff);
$red = imagecolorallocate($im, 0xff, 0x00, 0x00);
$blue = imagecolorallocate($im, 0x00, 0x00, 0xff);
imagettftext($im, 8, 30, 10, 100, $red, "Times", "HUCE - 46pm1");
imagettftext($im, 10, -30, 10, 10, $blue, "Arialni", "HUCE - 46pm1");
$im2 = imagecreate(200, 200);
//imagecoyresiWed,$im2' $im' A' A' A' A' 2AA' 2AA' 4AA' 4AA-<
imagecopyresampled($im2, $im, 0, 0, 0, 0, 200, 200, 100, 100);
imagegif($im2);
?>
VII.5. Mu sc
.5.1. True color color index
.5.3. Knh alpha
VII.5.1. True coIor & coIor index
ly mu ca dim nh
D
$*olo% = !ma>$Bolo%2t(ima>$& ?& .)'
D
$+alu$s = !ma>$Bolo%so%!)d$?(ima>$& i)d$?)'
mageColorResolveAlpha()
mageAlphaBlending()
<?php
$im = ImageCreateTrueColor(150,150);
$white = ImageColorAllocate($im,255,255,255);
ImageAlphaBlending($im, true);
ImageFilledRectangle($im,0,0,150,150,$white);
$red = ImageColorResolveAlpha($im,255,50,0,63);
ImageFilledEllipse($im,75,75,80,50,$red);
$gray = ImageColorResolveAlpha($im,70,70,70,63);
ImageAlphaBlending($im, true);
ImageFilledRectangle($im,60,60,120,120,$gray);
header('Content-Type: image/png');
ImagePNG($im);
?>
IX. XML
X.1. Tao vn bn XML
X.2. c XML
IX.1. Tao vn bn XML
header('Content-Type: text/xml')
<?php
function sta%t_$l$m$)t($i)Ma%s$%& $i)Jam$& C$i)2tt%ibut$s)
{
+a%_dump($i)Jam$)'
+a%_dump($i)2tt%ibut$s)'
,
function $)d_$l$m$)t($i)Ma%s$%& $i)Jam$) {
+a%_dump($i)Jam$)'
,
$?ml = ?ml_pa%s$%_*%$at$()'
?ml_s$t_$l$m$)t_ha)dl$%($?ml& "sta%t_$l$m$)t"&
"$)d_$l$m$)t")'
?ml_pa%s$($?ml& "<?ml-<%o@ )am$=G%o@5G
at%=Gatt%ibut$5G/-</?ml-")'
?-
VIII. PDF
.1. Document Page
.2. Text
.3. mages Graphics
.4. Nagivations
.5. Cc chc nng khc