การพัฒนา web application ด้วยภาษา php เบื้อต้น part...
DESCRIPTION
การพัฒนา Web application ด้วยภาษา php เบื้องต้นTRANSCRIPT
การพั�ฒนา Web Application ด้วยภาษา
PHPPart 1.
สหชั�ย งามชั�ยภู�ม�[email protected]
ศู�นย�อบรม Brightest IDEA
www.brightest-idea.com
เน��อหาทำ�าความร� �จั�กก�บ PHPองค�ประกอบของการเข�ยนสคร�ปต์� PHP เคร !องม อและโปรแกรมทำ�!จัะต์�องใชั�การแทำรกค�าส�!ง PHPการประกาศูต์�วแปรต์�วดำ�าเน�นการการทำ�างานก�บ String
ทำ�าความร�จั�กก�บ PHP เป'นภูาษา Script ส�าหร�บแสดำงเว)บเพจั
อย+างหน,!ง จั�ดำอย�+ในกล-+ม Server Side Script การทำ�างานจัะแทำรกอย�+ในเอกสาร HTMLสามารถ Compile ไดำ�ทำ�0งบนระบบปฏิ�บ�ต์�การ UNIX, Windows
ความสามารถในการทำ�างานส�ง โดำยเฉพาะก�บการต์�ดำต์+อก�บ Database เชั+น MySQL, msSQL เป'นต์�น
องค�ประกอบของการเข ยนสคร"ปต์� PHPServerClientWeb Server
Apache IIS
องค�ประกอบของการเข ยนสคร"ปต์� PHP (ต์$อ)Text Editor
Adobe Dreamweaver, HTMLKit, Edit Plus, Notepad
Database Server MySQL, MS SQL Server
Database phpMyAdmin
เคร�%องม�อและโปรแกรมทำ %จัะต์องใช้ (ในว�นน �)Appserv (http://www.appservnetwork.com) Apache PHP MySQL phpMyAdmin
Text Editer Adobe Dreamweaver
การแทำรกค�าส�%ง PHPTag PHP
Short style: <? ………………. ?> XML style: <?php …………. ?> Script style: <SCRIPT
Language="php"> …….. </SCRIPT> ASP style: <% …………….. %>
แสด้งขอความโด้ยใช้ค�าส�%ง echo <html><head><title>Untitled Document</title></head><body>
<?echo “Hello World”;?>
</body></html>
Comment in PHP Comment หลายบรรทำ�ดำ
เร�!มต์�นดำ�วย /* จับดำ�วย */ เชั+น<?/*echo “Faculty of Informatics”;echo “Mahasarakham University”;*/?>
Comment บรรทำ�ดำเดำ�ยว ใชั� // ไว�หน�าค�าส�!ง เชั+น
<?// echo “Faculty of Informatics”;?>
การประกาศต์�วแปร ชั !อต์�วแปร ข,0นต์�น
ดำ�วยเคร !องหมาย$
ค+าทำ�!เก)บ
ร�ปแบบ
ต์�วอย+าง
ช้น"ด้ของต์�วแปร Integer
$num=20;Float
$num=1.5;String
$message=“Hello”;Array
$name=array(“sahachai",“worawith",“aphichart",“chalermchon");
ต์�วด้�าเน"นการ (Operator) ใน PHPArithmetic Operators
ต์�วด้�าเน"นการ (Operator) ใน PHP (ต์$อ)Assignment Operators
ต์�วด้�าเน"นการ (Operator) ใน PHP (ต์$อ)Comparison Operators
ต์�วด้�าเน"นการ (Operator) ใน PHP (ต์$อ)Logical Operators
การทำ�างานก�บ Stringaddslahes()
$str=“It 's Home.”; echo addslashes($str);
chr() $data = "65"; echo chr($data);
echo() echo "Hello Member";
การทำ�างานก�บ String (ต์$อ)explode()
$a = "A B C D E F";$b = explode(" ", $a);echo "$b[0], $b[1]";
htmlspecialchars()$a = "<B>Mahasarakham</B>";
print htmlspecialchars($a)
การทำ�างานก�บ String (ต์$อ)strlen()
$a = “Mahasarakham";print strlen($a);
strpos()$a = " Mahasarakham";print strpos($a, “ha");
strrev() $a = “Mahasarakham"; print strrev($a);
การทำ�างานก�บ String (ต์$อ)strstr()
$a = “Mahasarakham University"; $word = “sarakham"; if(strstr($a,$word)) {
echo "Found."; } else{ echo "Not Found."; }
การทำ�างานก�บ String (ต์$อ)strtolower()
$a = “MAHASARAKHAM University";
echo strtolower($a);strtoupper()
$a = " MAHASARAKHAM University";
echo strtoupper($a);
การทำ�างานก�บ String (ต์$อ)str_replace()
$a = “Mahasarakham University";$b = str_relpace("Mahasarakham", “Khon Kean", $a);echo $b;
trim()$a = " Faculty of Informatics MSU";$b = trim($a);
การทำ�างานก�บ String (ต์$อ)ucfirst()
$a = "what are you doing?";echo ucfirst($a);
ucwords()$a = "what are you doing?";echo ucwords($a);