nhom5 - Khai báo biến, xử lý chuỗi và mảng trong PHP

  • Published on
    12-Jun-2015

  • View
    2.982

  • Download
    1

Embed Size (px)

DESCRIPTION

H Tn c Thng . http://hoacuong.wordpress.com/

Transcript

Nhm 5

ti: Cch khai bo bin, x l chui v mng trong PHP

1

PHP l g?PHP l vit tt ca ch Personal Home Page ra i nm 1994 do pht minh ca Rasmus Lerdorf v n tip tc pht trin bi nhiu c nhn v tp th do PHP c xem l sn phm ca m ngun m.

2

PHP l g? PHP

l mt ngn ng lp trnh web c s dng nhiu nht, thch hp nht cho vic pht trin cc website va v nh. PHP c th c nhng vo cc trang HTML. PHP c s dng rng ri v ph bin nht xy dng cc cc trang web ng.3

PHP l g? PHP

da trn c php ca C Phn m PHP c t trong th m

4

Bin trong PHPKhai

bo bin Tm vc ca bin

5

Khai bo bin Tt

c nhng bin khai bo trong PHP u bt u vi du la ($) Khai bo bin c phn bit ch hoa v thng Vd: $abc = 5; $ABC = 10;

6

Khai bo bin Tn

bin ch c bao gm cc k t ch ci (a..z hoc A...Z), ch s (0...9) v k t gch di (_); nhng tn bin khng c bt u bng k t gch di hoc ch s v k t c bit. VD: $_abc Khng hp l! bt u bng k t gch di $1abc Khng hp l! bt u bng ch s $nguyn Khng hp l! tn bin c k t c bit ()

7

Khai bo bin Khi

khai bo bin th khng cn phi khai bo kiu d liu cho bin nh mt s ngn ng khc. Ch cn khai bo tn bin. VD: $a = Welcome to PHP; // y l bin chui $b = 2; // y cng l bin chui $c = 4; // y l bin s $d = 4.123; //y l bin s thc8

Tm vc ca bin Tm

vc ca bin l ng cnh m trong bin c nh ngha VD: 9

Tm vc ca binKhi gp 1 hm do ngi dng nh ngha, bn trong hm, bin cc b s c dng thay v bin ton cc 10

Tm vc ca bin truy cp ti cc bin ton cc bn trong 1 hm do ngi dng nh ngha, ta c th dng 1 trong 2 cch sau:

11

Tm vc ca bin Cch

1:

12

Tm vc ca bin Cch

2:

13

Chui trong PHP Tt

c cc chui u c bao trong du nhy i Trong mt chui m bn bao li bng cp nhy i ta c th chn thm bin vo gia m PHP vn hiu l bin VD: $name = An; $hello = Hello,Ten toi la $name; echo $hello; //ket qua: Hello,Ten toi la An14

Chui trong PHP Nu

trong chui mun c cha cc k t c bit nh ,\,$...... Ta phi s dng k t chuyn \ trc cc k t c bit. VD: echo Hello,Ten toi la \An\ //kt qu: Hello,Ten toi la An

15

Chui trong PHPi vi du nhy nNu chui c cha cc bin c bao li bng du nhy n th bin s b bin thnh chui. VD: $name = An; echo Hello,Ten toi la $name; //kt qu: Hello,Ten toi la $name

16

Chui trong PHP Ta

c th s dng du Here Documents. Xc nh gii hn u chui vi du