Professional Documents
Culture Documents
WebLec7 PHP
WebLec7 PHP
CS380
URLs and web servers
3
http://server/path/file
Та хөтөч дээрээ URL оруулахдаа ихэвчлэн:
Таны компьютер DNS ашиглан серверийн IP хаягийг хайж
байна
Таны хөтөч тэр IP хаяг руу холбогдож, өгөгдсөн файлыг
хүсэх болно
Вэб серверийн програм хангамж (жишээ нь Apache)
серверийн дотоод файлын системээс тухайн файлыг татаж
авдаг
Сервер таны агуулгыг буцааж илгээдэг

URLs and web servers (cont.)
4
Apache, Websphere
SW(Java Servlets, XML
Files)
http://www.facebook.com/home.php
Зарим URL-ууд нь вэб серверийн ажиллах ёстой
програмуудыг зааж өгсөн бөгөөд үр дүнд нь үр
дүнгээ танд буцааж илгээдэг:
Дээрх URL нь facebook.com серверт home.php
программыг ажиллуулж, гаралтыг нь буцааж
илгээхийг хэлж байна

Server-Side web programming
6
Вэб сервер:
сервер талын програмуудыг ажиллуулах боломжийг
олгодог програм хангамжийг агуулдаг
вэб хүсэлтийн хариу болгон гаралтыг нь буцааж
илгээдэг
Хэл/фрэймворкуудын бүр өөрийн давуу болон сул
талуудтай
Үүнд PHP ашигладаг

What is PHP?
9
Hello.php
Hello world!
<?php
print "Hello, world!";
?> PHP
Hello world!
output

Viewing PHP output
13
Hello world!

2 PHP Basic Syntax
CS380
PHP syntax template
15
HTML content
<?php
PHP code
?>
HTML content
<?php
PHP code
Contents of a .php file between <?php and ?> are executed as PHP code
?> All other contents are output as pure HTML
HTML content
We can switch back... and forth between HTML and PHP "modes" PHP

PHP syntax template
16
print "text";
$name = expression;
PHP
$user_name = “mundruid78";
$age = 16;
$drinking_age = $age + 5;
$this_class_rocks = TRUE;
PHP

Variables
19
+ - * / % . ++ --
= += -= *= /= %= .=
Олон операторууд төрлийг автоматаар хөрвүүлдэг:
5 + "7" is 12
CS380

Comments
23
# single-line comment
// single-line comment
/*
multi-line comment
*/ PHP
$favorite_food = "Ethiopian";
print $favorite_food[2];
$favorite_food = $favorite_food . "
cuisine";
print $favorite_food;
PHP

String Type
25
# index 0123456789012345
$name = "Stefanie Hatcher";
$length = strlen($name);
$cmp = strcmp($name, "Brian Le");
$index = strpos($name, "e");
$first = substr($name, 9, 5);
$name = strtoupper($name);
PHP

String Functions (cont.)
27
$age = 16;
print "You are " . $age . " years
old.\n";
print "You are $age years old.\n"; #
You are 16 years old.
PHP

Interpreted Strings
29
$name = “Xenia";
$name = NULL;
if (isset($name)) {
print "This line isn't going to be
reached.\n";
} PHP

Interpreted Strings (cont.)
32
$feels_like_summer = FALSE;
$php_is_great = TRUE;
$student_count = 7;
$nonzero = (bool) $student_count; #
TRUE
PHP
CS380

bool (Boolean) type
35
if (condition) {
statements;
} elseif (condition) {
statements;
} else {
statements;
}
PHP

while loop (same as Java)
37
while (condition) {
statements;
} PHP
do {
statements;
} while (condition);
PHP

Math operations
38
$a = 3;
$b = 4;
$c = sqrt(pow($a, 2) + pow($b, 2));
PHP
math functions
abs ceil cos floor log log10 max
min pow rand round sin sqrt tan
math constants
M_PI M_E M_LN2

Int and Float Types
$a = 7 / 2; # float: 3.5
$b = (int) $a; # int: 3
$c = round($a); # float: 4.0
$d = "123"; # string: "123"
$e = (int) $d; # int: 123
PHP
бүхэл тоон хувьд int, реалын хувьд float
хоёр int утгыг хуваах нь хөвөгчийг үүсгэж болно
XAMPP Installation
40
Windows-тэй суулгах:
XAMPP вэбсайт руу ороод XAMPP Windows-ийг
сонгоно уу. https://www.apachefriends.org/download.html
Хамгийн сүүлийн үеийн хувилбарыг сонгоод
суулгагч файл дээр дарж татаж авч эхэлнэ.
Windows-д зориулсан XAMPP нь гурван өөр
хувилбараар суулгах боломжтой

XAMPP Installation
41