phpЦԒ
l(f)r(sh)g:2017-01-18 (li)Դ: ĬЦԒ c(din)
phpЦԒƪһPHPW(xu)(x)ęn
PHP (jin)http://phalanger.codeplex.com /1.ʲô PHP PHP ָ PHP:ıA(y)̎gעPHP: Hypertext Preprocessor fw? PHPһN(w)˵_Z(y)ԣ ASP ? PHP _ڷ(w)ψ(zh) ? PHP ֺ֧ܶ(sh)(j)(k)MySQLInformixOracleSybaseSolid PostgreSQLGeneric ODBC ȵȣ ? PHP һ(g)_Դܛopen source softwareOSS2.ļ ʲô PHP ļPHP ļɰıHTML (bio)Լ_ PHP ļ?yn)g[ؼ HTML PHP ļļY ".php"".php3" ".phtml"3ʲô MySQL ? MySQL һN(sh)(j)(k)(w) ? MySQL ֧֘(bio)(zhn) SQL ? MySQL Sƽ_(ti)Ͼg4PHP+MySQL PHP c MySQL ĽMǿƽ_(ti) ˼ Windows h(hun)M(jn)_l(f) Unix ƽ_(ti)ṩ (w)5ʲôҪʹ PHP ? PHP ڲͬƽ_(ti)\(yn)УWindowsLinuxUnix ? PHP cĿǰеڱʹõķ(w)ݣApacheIIS ȣ
? PHP ڌW(xu)(x)ɸЧ\(yn)ڷ(w)6 PHP Z(y) <?php ?> PHP _K <?php _ʼ ?> Y(ji) PHP _Kęnеκλ(dng)Ȼֺ֧(jin)ķ(w)ʹ <? ?> (li)_ʼͽY(ji)_K7(sh) php ݔıPHP ļͨ(hu) HTML (bio)һ(g) HTML ļԼһЩ PHP_a҂ṩһκ(jin)ε PHP _?yn)g[ݔı "Hello World"ЃɷNͨ^(gu) PHP (li)ݔıĻA(ch)ָecho print҂ʹ echo Z(y) (li)ݔı "Hello World"<html> <body><?php echo "Hello World"; ?></body> </html>8 PHP ҂ʹ // (li)עʹ /* */ (li)עጉK9PHP е׃ ׃ڴ惦(ch)ֵ电(sh)ıַ(sh)MһO(sh)ij(g)׃҂Ϳ_؏(f)ʹPHP е׃ $ ̖(ho)_ʼ
PHP O(sh)׃_ǣ$var_name = value;PHP T(hu)ӛ׃ǰ $ ̖(ho)ǘԒ׃ǟo(w)Ч҂?c)?chung)һ(g)ַ׃һ(g)Д(sh)ֵ׃<?php $txt = "Hello World!"; $number = 16; ?>10PHP һTɢ͵Z(y)ԣLoosely Typed Language һTɢ͵Z(y)ԣ PHP ҪO(sh)׃֮ǰԓ׃У PHP ԓ׃Ĕ(sh)(j)͡(j)׃O(sh)õķʽPHP (hu)Ԅ(dng)ذ׃D(zhun)Q_Ĕ(sh)(j)ڏ(qing)͵ľZ(y)Уʹǰ׃ͺQ PHP ׃(hu)ʹÕr(sh)Ԅ(dng)11׃Ҏ(gu)t ׃Ҏ(gu)t? ׃ĸ "_" _^ ? ׃ֻܰĸ(sh)ַԼ ? ׃ܰո׃ɶ(g)~Mɣô(yng)ԓʹM(jn)зָ$my_stringԴĸ_^ $myString12PHP еַ ַ׃ڰֵַڱ̳У҂Bׂ(g) PHP ڲַõĺ(sh)\(yn)ڄ(chung)ַ֮҂ͿԌ(du)M(jn)вֱں(sh)ʹַ߰惦(ch)׃
13\(yn)Concatenation Operator \(yn) PHP Уֻһ(g)ַ\(yn)\(yn) (.) ڰуɂ(g)ֵַB(li)Ҫуɂ(g)׃BһՈ(qng)ʹ@(g)c(din)\(yn) (.) 14ʹ strlen() (sh) strlen() (sh)Ӌ(j)ַL(zhng)҂ַ "Hello world!" L(zhng)ȣַL(zhng)Ϣѭh(hun) (sh)?yn)Ǖr(sh)_ַΕr(sh)Y(ji)ǺҪģѭh(hun)У҂ Ҫַеһ(g)ַ֮Y(ji)ѭh(hun)<?php echo strlen("Hello world!"); ?>15ʹ strpos() (sh) strpos() (sh)ַ(ni)zһַһ(g)ַַҵƥ䣬ԓ(sh)(hu)صһ(g)ƥλδҵƥt FALSE҂?c)һDzַҵַ?"world"<?php echo strpos("Hello world!","world"); ?>ϴaݔǣ6ģ҂ַַ "world" λ 6 6 7ַе ׂ(g)λõ 0 1
16\(yn)f(shu)ӽY(ji)+Additionx=2 x+24-Subtractionx=2 5-x3*Multiplicationx=4 x*520/Division15/5 5/23 2.5%Modulus (division remainder)5%2 10%8 10%21 2 0++Incrementx=5 x++x=6--Decrementx=5 x--x=4xֵ\(yn)\(yn)f(shu)=x=yx=y+=x+=yx=x+y-=x-=yx=x-y*=x*=yx=x*y/=x/=yx=x/y
phpЦԒƪphpԇ},(jng)phpPԇ}c
(wn)}
1 xmĴհ̎
PHP һN_______Z(y)______PHP Á(li)_l(f)(dng)B(ti)______(ni)
ݣͬ߀ɱÁ(li)______Լęn
A(dng)B(ti)PHP(sh)(j)(k)HTML
BǶʽZendHTMLXML
C Perl ģPHPWeboB(ti)
DǶʽZendDocbook ęnMySQL
E Zend PHPDHTML
1 ΨһxĴ BPHP һN Zend _Z(y)ԣͨǶ HTML
aҪÁ(li)_l(f) HTML ęnҲ(li)_l(f)͵ęn
XML
2ķN(bio) PHP ʼ/Y(ji)
A<% %>
B//
C<?php ?>
D/* */
E
2 PHP У˂̫ʹ<% %>̓ɂ(g)(bio)_(sh)ǺϷ PHP 綨
(bio)ǷǷģ_Ĵ Dӛס(j) php.ini ļеòͬ@
(dng)еijЩ(bio)o(w)ضrʹ
3´aĂ(g) PHP Z(y)
A$_10
B${MyVar}
C&$something
D$10_somethings
E$aVaR
3 PHP ׃һ(g)Ԫ̖(ho)_^┵(sh)Ĕ(sh)ĸ${MyVar}
һ(g)Ϸ׃ʹõ^ɢs&$something nj(du)$something
Ȼ׃Ԕ(sh)֞_^$10_somethings ǷǷģ˴ D
4\(yn)´a@ʾʲô
define(myvalue, "10");
$myarray[10] = "Dog";
$myarray[] = "Human";
$myarray['myvalue'] = "Cat";
$myarray["Dog"] = "Cat";
print "The value is: ";
print $myarray[myvalue]."\n";
?>
2
AThe Value is: Dog
BThe Value is: Cat
CThe Value is: Human
DThe Value is: 10
EDog
4 ע$myarray Iֵ]д̖(ho)L(wn)I myvalue ַ
dz myvalue ֵKL(wn)$myarray[10]ֵ Dog A
5 print() echo()ʲô^(q)e
Aprint()_(d)ʽһecho()
Becho()_(d)ʽһ֣print()
Cecho() CLIУ汾 PHP ʹprint()
Dprint() CLIУ汾 PHP ʹecho()
E]Ѕ^(q)eɂ(g)(sh)ӡı
5 M print() echo()ڽ^(sh)r¿ԻQʹ֮g߀һ̎ͬ
print()Ǻ(sh)зֵecho()(sh)Hһ(g)Z(y)ԽY(ji)(gu)]зֵҲڱ
_(d)ʽʹá A
6_ݔʲô
$a = 10;
$b = 20;
$c = 4;
$d = 8;
$e = 1.0;
$f = $c + $d * 2;
$g = $f % 20;
$h = $b - $a + $c + 2;
$i = $h << $c;
$j = $i * $e;
print $j;
?>
A128
B42
C242.0
D256
E342
6 %\(yn)ʾȡģɂ(g)(sh)(sh)<<\(yn)ஔ(dng)ڳ 2
N ηĴ𰸳һ(g)c(din)(sh)׃Ĕ(sh)(j)С(sh)c(din)
ݔĽY(ji)С(sh)֡ 256D
7νo׃$a$b $c xֵʹ_@ʾַHello, World!? $string = "Hello, World!";
$a = ?;
3
$b = ?;
$c = ?;
if($a) {
if($b && !$c) {
echo "Goodbye Cruel World!";
} else if(!$b && !$c) {
echo "Nothing here";
}
}
else {
if(!$b) {
if(!$a && (!$b && $c)) {
echo "Hello, World!";
} else {
echo "Goodbye World!";
}
phpЦԒƪPhp+Access(jin)εӛ䛲
WAMP5bɺy(c)ԇIIS+PHP5y(c)ԇ_
1 ½access2003(sh)(j)(k)ļdata.mdb(sh)(j)student:
Id(Ԅ(dng)̖(ho)),xh,xm,xb,dh,bz
2g[ͨӍdata.mdb(sh)(j)(k)µĔ(sh)(j)ļIndex.php
<?php
$conn=new com("adodb.connection");
$connstr="driver={microsoft access driver (*.mdb)};dbq=".realpath("data.mdb");
$conn->open($connstr);
$rs=new com("adodb.recordset");
$rs->open("select * from student ",$conn,1,1);
?>
<table width=600 align=center border=1>
<tr><td width=100>W(xu)̖(ho) <td width=100><td width=40>Ԅe<td width=100>Ԓ<td>؞</td><td>h<td></td>
<?php
while(!$rs->eof){
$id = $rs->Fields(0)->value;
?>
<tr>
<td><?php echo $rs["xh"];?>
<td><?php echo $rs["xm"];?>
<td><?php echo $rs["xb"];?>
<td><?php echo $rs["dh"];?>
<td><?php echo $rs["bz"];?>
<td><a onclick="return confirm('_Ҫ?jing)hӛ䛆')" href="dele.php?id=<?php echo $rs["id"];?>">h</a></td>
<td><a href="edit.php?id=<?php echo $rs["id"];?>"></a></td>
<?php
$rs->movenext();
}
?>
<a href="add.php"></a>
3ӛļAdd.php
<form action="addins.php" name="myform" method="POST")>
W(xu)̖(ho)<input name="xh" id="mytitile" type="text"><br>
<input name="xm" id="mytitile" type="text"><br>
Ԅe<input name="xb" id="mytitile" type="text"><br>
Ԓ<input name="dh" id="mytitile" type="text"><br>
סַ<input name="bz" id="mytitile" type="text"><br>
<input name="mysubmit" id="mysubmit" type="submit" value="ύ" >
</form>
ӛ䛺_(ti)ļAddins.php
<?php
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".realpath("data.mdb"); $conn->Open($connstr);
$rs = new com("ADODB.RecordSet");
$rs->Open("select * from student",$conn,1,1);//_ӛ䛼
$xh1=$_POST["xh"];
$xm1=$_POST["xm"];
$xb1=$_POST["xb"];
$dh1=$_POST["dh"];
$bz1=$_POST["bz"];
if(empty($xh1)){
echo "<script>alert('W(xu)̖(ho)ܞ');window.history.back(-1);</script>";
}
else{if(empty($xm1)){
echo "<script>alert('ܞ');window.history.back(-1);</script>";
}
}
$conn->execute("insert into [student] (xh,xm,xb,dh,bz)
('$xh1','$xm1','$xb1','$dh1','$bz1')");
echo "<script>alert('ӳɹ');window.location.href='index.php';</script>";
?>
4hӛļDele.php
<?php
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("db1.mdb"); $conn->Open($connstr);
$idh=$_GET['id'];
$query="deletefromtxl where id=$idh";
$result=$conn->Execute($query);
if($result)
echo "<script>alert('hɹ');window.location.href='index.php';</script>"; else
echo "<script>alert('hʧ');window.location.href='index.php';</script>";
?>
5ӛļ
(1)ļedit.php
<?php
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".realpath("data.mdb"); $conn->Open($connstr);
$rs = new com("ADODB.RecordSet");
$idh=$_GET['id'];
$rs->Open("select * from student where id=$idh",$conn,1,1);//_ӛ䛼 values
?>
<form action="save1.php" name="myform" method="POST")>
<input type="hidden" name="id" value=<?php echo $rs["id"];?>><br>
W(xu)̖(ho)<i
nput type="text" name="xh" value=<?php echo $rs["xh"];?>><br><input type="text" name="xm" value=<?php echo $rs["xm"];?>><br>
Ԅe<input type="text" name="xb" value=<?php echo $rs["xb"];?>><br>
Ԓ<input type="text" name="dh" value=<?php echo $rs["dh"];?>><br>
סַ<input type="text" name="bz" value=<?php echo $rs["bz"];?>><br>
<input name="mysubmit" id="mysubmit" type="submit" value="ύ" >
</form>ĺĺ_(ti)ļmodify.php
<?php
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".realpath("data.mdb"); $conn->Open($connstr);
//$rs = new com("ADODB.RecordSet");
//$rs->Open("select * from student",$conn,3,3);//_ӛ䛼
$idh=$_POST["id"];
$xh1=$_POST["xh"];
$xm1=$_POST["xm"];
$xb1=$_POST["xb"];
$dh1=$_POST["dh"];
$bz1=$_POST["bz"];
$sql="update student set xh='$xh1',xm='$xm1',xb='$xb1',dh='$dh1',bz='$bz1' where id=".$idh; $resulte = $conn->Execute($sql);
if($resulte)
echo "<script>alert('ijɹ');window.location.href='index.php';</script>"; else
echo"hʧ";
header("location:index.php");
?>
P(gun)~ЦԒ php phpЦԒW(wng)վԴa ЦԒȫ Ц
c(din)x