"; echo "Today is " . date("Y.m.d") . "
"; echo "Today is " . date("Y-m-d") . "
"; echo "Today is " . date("l"); ?> "> "; echo "Today is " . date("Y.m.d") . "
"; echo "Today is " . date("Y-m-d") . "
"; echo "Today is " . date("l"); ?> ">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP Lecture 11 Kanida Sinmai

Similar presentations


Presentation on theme: "PHP Lecture 11 Kanida Sinmai"— Presentation transcript:

1 PHP Lecture 11 Kanida Sinmai ksinmai@hotmail.com

2 Date and Time date(format,timestamp) <!DOCTYPE html>
<body> <?php echo "Today is " . date("Y/m/d") . "<br>"; echo "Today is " . date("Y.m.d") . "<br>"; echo "Today is " . date("Y-m-d") . "<br>"; echo "Today is " . date("l"); ?> </body> </html>

3 Time zone Check server time zone
<?php date_default_timezone_set("America/New_York"); echo "The time is " . date("h:i:sa"); ?> Check server time zone echo 'date.timezone: ' . ini_get('date.timezone');

4 Arrays <?php $cars = array("Volvo", "BMW", "Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?>

5 The count() Function <?php $cars = array("Volvo", "BMW", "Toyota"); echo count($cars); ?>

6 Array: Loop <?php $cars = array("Volvo", "BMW", "Toyota"); $arrlength = count($cars); for($x = 0; $x < $arrlength; $x++) { echo $cars[$x]; echo "<br>"; } ?>

7 PHP - Sort Functions For Arrays
<!DOCTYPE html> <html> <body> <?php $cars = array("Volvo", "BMW", "Toyota"); rsort($cars); $clength = count($cars); for($x = 0; $x <  $clength; $x++) {      echo $cars[$x];      echo "<br>"; } ?> </body> </html> Sort Array in Descending Order - rsort()

8 PHP - Sort Functions For Arrays
<!DOCTYPE html> <html> <body> <?php $cars = array("Volvo", "BMW", "Toyota"); sort($cars); $clength = count($cars); for($x = 0; $x <  $clength; $x++) {      echo $cars[$x];      echo "<br>"; } ?> </body> </html> Sort Array in Ascending Order - sort()

9 PHP Global Variables - Superglobals
$_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION

10 $GLOBALS $GLOBALS is a PHP super global variable which is used to access global variables from anywhere in the PHP script (also from within functions or methods). PHP stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable.

11 Example <?php $x = 75; $y = 25; function addition() { $GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y']; } addition(); echo $z; ?>

12 $_SERVER $_SERVER is a PHP super global variable which holds information about headers, paths, and script locations. <?php echo $_SERVER['PHP_SELF']; echo "<br>"; echo $_SERVER['SERVER_NAME']; echo $_SERVER['HTTP_HOST']; echo $_SERVER['HTTP_REFERER']; echo $_SERVER['HTTP_USER_AGENT']; echo $_SERVER['SCRIPT_NAME']; ?>

13 $_REQUEST, $_POST, $_GET
PHP $_REQUEST is used to collect data after submitting an HTML form.

14 PHP Forms - POST <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> <input type="text" name=" "><br> <input type="submit"> </form> </body> </html>

15 welcome.php <html> <body> Welcome <?php echo $_POST["name"]; ?><br> Your address is: <?php echo $_POST[" "]; ?> </body> </html>

16 PHP form - GET <html> <body> <form action="welcome_get.php" method="get"> Name: <input type="text" name="name"><br> <input type="text" name=" "><br> <input type="submit"> </form> </body> </html>

17 welcome_get.php <html> <body> Welcome <?php echo $_GET["name"]; ?><br> Your address is: <?php echo $_GET[" "]; ?> </body> </html>

18 GET vs. POST $_GET is an array of variables passed to the current script via the URL parameters. $_POST is an array of variables passed to the current script via the HTTP POST method.

19 When to use GET? GET method is visible to everyone
The limitation is about 2000 characters. GET may be used for sending non-sensitive data.

20 When to use POST? the POST method is invisible to others.
has no limits on the amount of information to send. Developers prefer POST for sending form data.

21 Exercise เขียนโปรแกรมรับค่ารับค่าตัวเลข 1 ค่า แล้วนำตัวเลขนั้นไปคำนวณหาเลขยกกำลัง 3 เขียนโปรแกรมรับชื่อ วันเดือนปีเกิด จากนั้นให้แสดงชื่อ วันเดือนปีเกิด และอายุของคนๆ นั้น ให้รับค่าตัวเลข 10 แล้วให้แสดงผลโดยเรียงจากเลขมากไปหาน้อย


Download ppt "PHP Lecture 11 Kanida Sinmai"

Similar presentations


Ads by Google