PHP HTML script tag script languagePHP PHP fragment

  • Slides: 68
Download presentation

การเขยน PHP แทรกอยกบ รปแบบ HTML script tag <script language="PHP"> PHP fragment <? php ?

การเขยน PHP แทรกอยกบ รปแบบ HTML script tag <script language="PHP"> PHP fragment <? php ? > PHP fragment ยอ <? ? > Expression tag <? = ? > ASP style <% %> HTML 5

HTML script tag <script language="PHP"> php_instructions </script>

HTML script tag <script language="PHP"> php_instructions </script>

ตวอยางการใช <script> tag <html> <head> <title><script language="PHP">echo "Hello world"</script></title> </head> <script language=“PHP”> echo "<h

ตวอยางการใช <script> tag <html> <head> <title><script language="PHP">echo "Hello world"</script></title> </head> <script language=“PHP”> echo "<h 1>First PHP Example</h 1>n"; echo "Welcome to PHP programming. "; echo "Today : ", date("r"), " (server time) "; echo "<p align=center><a href=index. html>Home</a>n<hr>"; echo "<div align="right">PHP. example by Sumet Angkasirikul"; </script> </html>

PHP. fragment <? php_instructions ? >

PHP. fragment <? php_instructions ? >

ตวอยาง <? php ? > fragment <html> <head> <title><? php echo "Hello world" ?

ตวอยาง <? php ? > fragment <html> <head> <title><? php echo "Hello world" ? ></title> </head> <? php echo "<h 1>First PHP Example</h 1>n"; echo "Welcome to PHP programming. "; echo "Today : ", date("r"), " (server time) "; echo "<p align=center><a href=index. html>Home</a>n<hr>"; echo "<div align="right">PHP. example by Sumet Angkasirikul"; ? > </html>

PHP fragment แบบสน <? php_instructions ? >

PHP fragment แบบสน <? php_instructions ? >

ตวอยางการใช <? ? > tag <html> <head> <title><? echo “Hello world” ? ></title> </head>

ตวอยางการใช <? ? > tag <html> <head> <title><? echo “Hello world” ? ></title> </head> <? echo "<h 1>First PHP Example</h 1>n"; echo "Welcome to PHP programming. "; echo "Today : ", date("r"), " (server time) "; echo "<p align=center><a href=index. html>Home</a>n<hr>"; echo "<div align="right">PHP. example by Sumet Angkasirikul"; ? > </html>

ตวอยางการใช <? = ? > tag <html> <head> <title><? = "Hello World" ? ></title>

ตวอยางการใช <? = ? > tag <html> <head> <title><? = "Hello World" ? ></title> </head> <body> <h 1><? = "First PHP Example" ? ></h 1> Welcome to PHP programming. Today : <? = date("r")? > (server time) <p align=center><a href=<? = "index. html" ? >>Home</a><hr> <div align="right">PHP. example by Sumet Angkasirikul</div> </body> </html>

ผลลพธทสงกลบ Browser <html> <head> <title>PHP Example by Aj. Sumet : example 2 -1. 1

ผลลพธทสงกลบ Browser <html> <head> <title>PHP Example by Aj. Sumet : example 2 -1. 1 a</title> </head> <body> <h 1>First PHP Example</h 1> Welcome to PHP programming. Today : Sat, 26 Feb 0700+ 13: 51: 46 2005 )server time) <p align=center><a href=index. html>Home</a> <hr><div align="right">PHP. example by Sumet Angkasirikul</body> </html>

ตวอยางการใช white space <? $user. Name = “Arnold Palmer” ; $user. Title = “The

ตวอยางการใช white space <? $user. Name = “Arnold Palmer” ; $user. Title = “The Premier”; $printed. Title = $user. Name. “ : “. $user. Title ; echo $printed. Title ? >

ตวอยางการใช echo <Html> echo $lucky. No; <head> echo " "; <title>Example 2. 1. 1

ตวอยางการใช echo <Html> echo $lucky. No; <head> echo " "; <title>Example 2. 1. 1 a Echo</title> echo "Time now : ". date("r"). ". n" ; </head> echo "See you, Bye. " <body> ? > <? </body> $lucky. No = 9; echo "Hello world. "; echo "This is echo example. n"; echo "Lucky no. is "; </html>

ผลลพธบนจอเวบบราวเซอร Hello world. This is echo example. Lucky no. is 9 Time now :

ผลลพธบนจอเวบบราวเซอร Hello world. This is echo example. Lucky no. is 9 Time now : Mon, 8 Nov. 0700+ 23: 28: 23 2004 See you, Bye.

Source code ภาษา html <Html> <head> <title>Example 2. 1. 1 a Echo</title> </head> <body>

Source code ภาษา html <Html> <head> <title>Example 2. 1. 1 a Echo</title> </head> <body> Hello world. This is echo example. Lucky no. is 9 Time now : Mon, 8 Nov. 0700+ 23: 32: 04 2004 See you, Bye. </body> </html>

ผลลพธ HTML <Html> <head> <meta http-equiv="Content-Type" content="text/html; charset=tis-"620> <title>PHP Example by Aj. Sumet :

ผลลพธ HTML <Html> <head> <meta http-equiv="Content-Type" content="text/html; charset=tis-"620> <title>PHP Example by Aj. Sumet : example 2. 1. 2 -2</title> </head> <body> ตวเลข รายรบ 307200 บาท รายจาย 92160 บาท คงเหลอสทธ 215040 บาท สวสด </body> </html>

ตวอยาง <? /* Example 2. 1. 2 a : Comment example. /* # this

ตวอยาง <? /* Example 2. 1. 2 a : Comment example. /* # this is 1 st php code fragment $title. Msg=“Example 2. 1. 2 a : comment”; $hello = “Hello world”; ? > <HTML> <head> <title><? echo $title. Msg; // send out title message from var. ? ></title> </head> <body> <h 1><? = $hello; // Just send out hello world to browser ? ></h 1> </body> </html>

ชอ identifier Case-sensitive ยกเวน standard function ไมมขอจำกดดานความยาว ไมซำกบ Reserved word ของ PHP

ชอ identifier Case-sensitive ยกเวน standard function ไมมขอจำกดดานความยาว ไมซำกบ Reserved word ของ PHP

ตวอยางการตงชอทถกตอง Score user. Account Address 01 วนทปอน last_modified_date valid. Account

ตวอยางการตงชอทถกตอง Score user. Account Address 01 วนทปอน last_modified_date valid. Account

ชนดขอมล Boolean Integer Float/double String Array Object Resource Null

ชนดขอมล Boolean Integer Float/double String Array Object Resource Null

Floating Point Literal ตวเลขทศนยม -589. 25 , 8009887. 1258 , 0. 001547 Scientific notation

Floating Point Literal ตวเลขทศนยม -589. 25 , 8009887. 1258 , 0. 001547 Scientific notation 25. 8 e-6 , -0. 0147 e-8 , 5. 0 e 16

String Literal (double quote) Multiple line $a = “This is a long message. We

String Literal (double quote) Multiple line $a = “This is a long message. We can extend this message to multiple line. ” Embedded variable $user 1 = “Arnold”; $est. Yr = 1958; $hello = “Member $user 1, Welcome”; //result: Member Arnold, Welcome $est. Msg = “Our organization was established in $est. Yr. ”

String Literal (double quote) Embedded variable $user 1 = “Arnold”; $est. Yr = 1958;

String Literal (double quote) Embedded variable $user 1 = “Arnold”; $est. Yr = 1958; $hello = “Member $user 1, Welcome”; //result: Member Arnold, Welcome $est. Msg = “Our organization was established in $est. Yr. ” $msg = “Item no. {$item[2]} : quantity {$order->quan} : status OK”

ตวอยางการใชตวแปร <? /* Example 2. 1. 3 a : variable */ $a = 3200;

ตวอยางการใชตวแปร <? /* Example 2. 1. 3 a : variable */ $a = 3200; $b = 7; $c = $a * $b / 100; ? > <html> <head><title> Example 2. 1. 3 a : variable usage. </title></head> <body> <p><u>Example 2. 1. 3</u> <p><? = “$a * $b % = $c” ? > <p><? = “The value of variable D is now $d“ // $d is not declared? > </body>

Type casting operator (type) expression เชน $quan = (int) $mquan; คำทใชกำหนดชอ boolean หรอ bool

Type casting operator (type) expression เชน $quan = (int) $mquan; คำทใชกำหนดชอ boolean หรอ bool int หรอ integer float / double หรอ real string, array, object type

Type casting function settype(expression, type ) ตวอยาง $quan = settype($mquan, ”integer”);

Type casting function settype(expression, type ) ตวอยาง $quan = settype($mquan, ”integer”);

การแปลงเปน array จาก Boolean, integer, float, string, resource ใหเปน array จะได array 1 element

การแปลงเปน array จาก Boolean, integer, float, string, resource ใหเปน array จะได array 1 element ทม index เปน [0[ จาก object จะได associative array ทม string ตามชอ variable ของ object index เปน

Operators Mathematics +, -, *, /, % (modulus) Assignment =, +=, -=, *=, /=,

Operators Mathematics +, -, *, /, % (modulus) Assignment =, +=, -=, *=, /=, %=, . = Incremental/decremental ++, -- (++pre/post++)

Operators Bitwise • &, |, ^, ~, << (shift left), >> (shift right) Comparison

Operators Bitwise • &, |, ^, ~, << (shift left), >> (shift right) Comparison • ==, !=, >, >=, <, <=, ) ===equal value & same type==! , ( Logical • AND &&, OR ||, ! การทำงานของ expression เปนแบบ short-circuit

Operators Conditional operator condition? expr 1: expr 2 $a=$y>1970? ”pass”: ”too young”; Error control

Operators Conditional operator condition? expr 1: expr 2 $a=$y>1970? ”pass”: ”too young”; Error control @ if(@fopen(“user. dat”, ”r”)) { … } String concatnate . $a = $b. “ baht”;

Functions Standard / Predefined functions • ภาษา PHP ม function เปนกลมตางๆ นบรอยกลม มจำนวนนบพนฟงกชน ด

Functions Standard / Predefined functions • ภาษา PHP ม function เปนกลมตางๆ นบรอยกลม มจำนวนนบพนฟงกชน ด PHP Manual User defined functions Function call • function. Identifier([arguments]) $a= round($b*20); echo “Password : “. str_repeat(“x”, $n); $now = time();