建站学院(LieHuo.Net)编程文档 本篇来介绍一些PHP入门级教程:快速学习PHP.
PHP的语法。
1、嵌入方法:
类似ASP的<%,PHP可以是<?php或者是<?,结束符号是?>,当然您也可以自己指定。
2、引用文件:
引用文件的方法有两种:require 及 include。
require 的使用方法如 require(”MyRequireFile.php”); 。这个函数通常放在 PHP 程序的最前面,PHP 程序在执行前,就会先读入 require 所指定引入的文件,使它变成 PHP 程序网页的一部份。常用的函数,亦可以这个方法将它引入网页中。
include 使用方法如 include(”MyIncludeFile.php”); 。这个函数一般是放在流程控制的处理部分中。PHP 程序网页在读到 include 的文件时,才将它读进来。这种方式,可以把程序执行时的流程简单化。
3、注释方法:
以下为引用的内容: <?php echo “这是第一种例子。n” ; // 本例是 C 语法的注释 /* 本例采用多行的 注释方式 */ echo “这是第二种例子。n” ; echo “这是第三种例子。n” ; # 本例使用 UNIX Shell 语法注释 |
4、变量类型:
以下为引用的内容: $mystring = “我是字符串” ; $NewLine = “换行了n” ; $int1 = 38 ; $float1 = 1.732 ; $float2 = 1.4E 2 ; $MyArray1 = array( “子” , “丑” , “寅” , “卯” ); |
这里引出两个问题,首先PHP变量以$开头,第二PHP语句以;结尾,可能ASP程序员会不适应。这两个遗漏也是程序上大多错误所在。
5、运算符号:
数学运算: 符号 意义
加法运算
- 减法运算
* 乘法运算
/ 除法运算
% 取余数
累加
– 递减
字符串运算:
运算符号只有一个,就是英文的句号。它可以将字符串连接起来,变成合并的新字符串。类似ASP中的&
以下为引用的内容: <? $a = “PHP 4″ ; |
这里也引出两个问题,首先PHP中输出语句是echo,第二类似ASP中的<%=变量%>,PHP中也可以<?=变量? >。
逻辑运算:
符号 意义
< 小于
> 大于
<= 小于或等于
>= 大于或等于
== 等于
!= 不等于
&& 而且 (And)
and 而且 (And)
|| 或者 (Or)
or 或者 (Or)
xor 异或 (Xor)
! 不 (Not)
php的流程控制
1、if..else 循环有三种结构
第一种是只有用到 if 条件,当作单纯的判断。解释成 “若发生了某事则怎样处理”。语法如下:
if (expr) { statement } |
其中的 expr 为判断的条件,通常都是用逻辑运算符号当判断的条件。而 statement 为符合条件的执行部分程序,若程序只有一行,可以省略大括号 {}。
范例:本例省略大括号。
以下为建站学院引用的内容: <?php if ($state==1)echo “哈哈” ; ?> |
这里特别注意的是,判断是否相等是==而不是=,ASP程序员可能常犯这个错误,= 是赋值。
范例:本例的执行部分有三行,不可省略大括号。
以下为引用的内容: <?php if ($state==1) { echo “哈哈 ; echo “<br>” ; } ?> |
第两种是除了 if 之外,加上了 else 的条件,可解释成 “若发生了某事则怎样处理,否则该如何解决”。语法如下
if (expr) { statement1 } else { statement2 } 范例:上面的例子来修改成更完整的处理。其中的 else 由于只有一行执行的指令,因此不用加上大括号。
以下为引用的内容: <?php if ($state==1) { echo “哈哈” ; echo “<br>”; } else{ echo “呵呵”; echo “<br>”; } ?> |
第三种就是递归的 if..else 循环,通常用在多种决策判断时。它将数个 if..else 拿来合并运用处理。
直接看下面的例子
以下为引用的内容: <?php if ( $a > $b ) { echo “a 比 b 大” ; } elseif ( $a == $b ) { echo “a 等于 b” ; } else { echo “a 比 b 小” ; } ?> |
上例只用二层的 if..else 循环,用来比较 a 和 b 两个变量。实际要使用这种递归 if..else 循环时,请小心使用,因为太多层的循环容易使设计的逻辑出问题,或者少打了大括号等,都会造成程序出现莫名其妙的问题。
2、 for 循环就单纯只有一种,没有变化,它的语法如下
for (expr1; expr2; expr3) { statement }
其 中的 expr1 为条件的初始值。expr2 为判断的条件,通常都是用逻辑运算符号 (logical operators) 当判断的条件。expr3 为执行 statement 后要执行的部份,用来改变条件,供下次的循环判断,如加一..等等。而 statement 为符合条件的执行部分程序,若程序只有一行,可以省略大括号 {}。
下例是用 for 循环写的的例子。
以下为引用的内容: <?php for ( $i = 1 ; $i <= 10 ; $i ) { echo “这是第”.$i.”次循环<br>” ; } ?> |
3、 switch 循环,通常处理复合式的条件判断,每个子条件,都是 case 指令部分。在实作上若使用许多类似的 if 指令,可以将它综合成 switch 循环。
语法如下
switch (expr) { case expr1: statement1; break; case expr2: statement2; break; default: statementN; break; }
其中的 expr 条件,通常为变量名称。而 case 后的 exprN,通常表示变量值。冒号后则为符合该条件要执行的部分。注意要用 break 跳离循环。
以下为引用的内容: <?php switch ( date ( “D” )) { case “Mon” : echo “今天星期一” ; break; case “Tue” : echo “今天星期二” ; break; case “Wed” : echo “今天星期三” ; break; case “Thu” : echo “今天星期四” ; break; case “Fri” : echo “今天星期五” ; break; default: echo “今天放假” ; break; } ?> |
这里需要注意的是break;别遗漏了,default,省略是可以的。
很明显的,上述的例子用 if 循环就很麻烦了。当然在设计时,要将出现机率最大的条件放在最前面,最少出现的条件放在最后面,可以增加程序的执行效率。上例由于每天出现的机率相同,所以不用注意条件的顺序。
构建数据库
在ASP中,如果是ACCESS数据库你可以直接打开ACCESS来编辑MDB文件,如果是 SQL SERVER你可以打开企业管理器来编辑SQL SERVER数据库,但是在PHP中,MY SQL的命令行编辑可能会令初学者感到很麻烦,不要紧,你下载一个PHPMYADMIN安装一下,以后建立编辑数据库可以靠它了。
下面说一下它的使用。
进入了phpmyadmin后,我们首先需要建立一个数据库,Language (*) 这里选择中文简体,然后在左边的 创建一个新的数据库 这里填写数据库名字,点击创建即可。
然后在左边下拉菜单中选择那个已经创建的数据库。在下面的
在数据库 shop 中创建一个新表 :
名字 :
字段数 :
中填写表名字和大致你认为的字段数(不够或者多了都不要紧,以后可以再添加或者缺省),按执行。
然后就可以开始建立表了。
第一栏是字段的名字;第二栏选择字段类型:
我们常用的是以下几个:
1)VARCHAR,文本类型
2)INT,整数类型
3)FLOAT,浮点数类型
4)DATE,日期型
5)大家或许会问,自动添加的ID在哪里?这个只要选择INT类型,在后面的额外中选择 auto_increment 就可以了。
波比源码 » PHP入门级教程:教你快速学习PHP语言
buy levaquin 250mg generic buy levofloxacin 500mg generic
purchase dutasteride sale order generic ondansetron ondansetron 8mg without prescription
buy indomethacin cefixime 200mg sale trimox pills
purchase arimidex online Viagra medication buy sildenafil 100mg without prescription
prednisone 40mg ca buy viagra 50mg without prescription oral sildenafil 100mg
buy ramipril 5mg sale buy temovate pills buy astelin generic
order buspirone 10mg generic buy buspirone 10mg generic ditropan drug
hytrin order azulfidine pills order sulfasalazine 500mg online
buy olmesartan pills order olmesartan 10mg diamox 250mg canada
order generic imdur 20mg buy generic imuran micardis 80mg pills
purchase imuran generic sildenafil pills 25mg order generic viagra
tadalafil 40mg pills phenazopyridine 200 mg without prescription order amantadine generic
buy avlosulfon sale allegra price oral perindopril 4mg
cost isotretinoin isotretinoin 20mg oral buy deltasone generic
lasix brand buy furosemide 100mg for sale order plaquenil 400mg
cheap cialis pills clomipramine 25mg us order clomipramine 50mg pills
order chloroquine generic order chloroquine sale order baricitinib 2mg pills
buy glycomet 500mg pills cialis 10mg order cialis 5mg online
order zyprexa 10mg pill olanzapine 10mg us order valsartan 80mg without prescription
order linezolid 600 mg online order linezolid 600 mg generic casino blackjack
prilosec cheap buy an essay cheap that roulette
order vardenafil 20mg for sale buy generic pregabalin 75mg methylprednisolone order
write essays for me help writing research paper viagra australia
priligy 90mg for sale order generic priligy 60mg cheap generic levothyroxine
buy orlistat 120mg sale buy xenical 60mg pill purchase zovirax
buy generic allopurinol 300mg crestor 20mg sale zetia sale
methotrexate for sale online brand methotrexate 10mg cheap reglan 20mg
buy cozaar 25mg generic buy losartan 25mg sale topamax 200mg generic
purchase zantac without prescription generic celecoxib 100mg celecoxib 200mg canada
doubleu casino online casino ocean casino online online casino games real money
tamsulosin 0.4mg canada ondansetron order spironolactone 100mg uk
generic cialis online cipro 1000mg canada buy cipro 1000mg pills
best casino casino online games cialis for men over 50
trazodone 100mg pills purchase trazodone without prescription buy sildenafil 50mg pills
academic writing uk stromectol 12mg ca ivermectin 8000
order sildalis generic purchase lamotrigine generic buy lamictal 200mg for sale
prednisone 20mg us isotretinoin 10mg us order amoxil pills
online roulette for real money buy tadalafil pills cialis 10mg price
zithromax usa order gabapentin 600mg generic neurontin 600mg pill
poker online best modafinil 200mg cost modafinil 100mg cheap
lasix over the counter doxycycline 100mg ca hydroxychloroquine over the counter
fildena 100mg usa sildenafil over the counter purchase budesonide sale
purchase tadacip for sale voltaren brand purchase indocin for sale
purchase singulair online cheap sildenafil 100mg us viagra 50mg usa
levitra vs cialis Buy cheap generic cialis oral cialis 40mg
stromectol price uk order amantadine dapsone 100mg usa
altace 10mg without prescription order etoricoxib online cheap order arcoxia 60mg for sale
recommended you read buy a custom essay cheap dissertation help
doxycycline 100mg for sale doxycycline tablet cleocin 150mg uk
order mesalamine buy azelastine 10 ml sprayers purchase avapro online cheap
buy generic clobetasol buy amiodarone 100mg for sale buy amiodarone 100mg pill
order olmesartan order olmesartan 20mg generic buy depakote online
diamox over the counter isosorbide for sale online order imuran 25mg online
lanoxin for sale online order lanoxin 250 mg molnunat pill
buy carvedilol generic buy amitriptyline 10mg online cheap buy elavil 10mg
indomethacin ca indocin over the counter buy cenforce pills
order pamelor 25mg pill purchase paxil without prescription order paxil 10mg generic
buy doxycycline 100mg online cheap medrol price buy medrol 8 mg online
buy requip 1mg online trandate 100 mg cheap buy trandate generic
buy tadalafil for sale amoxicillin order cost trimox 250mg
Thank you great posting about essential oil. Hello Administ . Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
order deltasone 5mg without prescription order amoxicillin 500mg generic buy amoxil 250mg online
buy isotretinoin generic buy prednisone 20mg without prescription ampicillin pill
albuterol 4mg price cheap amoxiclav buy generic augmentin 625mg
prednisolone uk buy neurontin 600mg generic buy lasix for sale
provigil 100mg brand buy lopressor online buy metoprolol generic
avodart 0.5mg sale avodart generic orlistat 60mg pill
oral doxycycline zovirax 400mg tablet buy acyclovir pill
buy ditropan generic buy prograf 1mg buy trileptal generic
cefdinir 300 mg usa cefdinir 300mg over the counter purchase pantoprazole
generic alfuzosin 10 mg diltiazem 180mg canada diltiazem 180mg over the counter
buy sildenafil 100mg without prescription viagra 100 mg tadalafil 40mg ca
medex price coumadin cost allopurinol online buy
buy zyrtec 10mg for sale order sertraline sale sertraline 50mg price
escitalopram 10mg uk order escitalopram 20mg pill revia 50mg ca
femara medication viagra overnight shipping usa order viagra for sale
canadian mail order pharmacies
tadalafil 5mg without prescription best price for cialis cheapest ed pills
cialis 5mg generic online ed medications top ed drugs
buy amoxicillin buy generic azithromycin 250mg buy prednisolone tablets
canadian pharmacy no prescription required
mexican pharmacy online
top mexican pharmacies
buy prednisolone 10mg online brand lasix buy generic lasix online
cheap canadian drugs
most reputable canadian pharmacies
tenormin over the counter methylprednisolone 16mg tablet purchase femara online
purchase albenza without prescription abilify 20mg ca order provera generic
buy cheap glycomet glycomet 500mg cost amlodipine medication
lyrica 150mg generic purchase claritin generic order dapoxetine 90mg online
canadian drug stores online
xenical ca zovirax 400mg without prescription buy generic allopurinol over the counter
buy crestor 20mg pill domperidone for sale buy motilium 10mg sale
buy imitrex generic sumatriptan 25mg us order avodart 0.5mg without prescription
cheap sumycin 250mg ozobax online cost baclofen 25mg
order generic zantac 300mg ranitidine 150mg uk order celebrex 100mg online
tamsulosin cost buy flomax pills for sale purchase aldactone sale
canadian mail order pharmacies to usa
buy combivent without prescription purchase combivent brand zyvox 600 mg
best canadian pharmacy for viagra
buy generic starlix 120mg nateglinide 120mg canada atacand generic
bystolic drug buy clozapine purchase clozaril
tegretol 200mg cheap buy lincocin 500 mg online order lincocin pills
buy cialis 20mg online cialis pills viagra usa
canadian online pharmacies
cost trimox 500mg buy biaxin buy clarithromycin paypal
tadalafil pills buy tadalafil 20mg pills oral tadalafil
buy azithromycin 250mg online cheap neurontin 100mg oral order gabapentin 800mg
stromectol 0.5 mg gnc ed pills buy prednisone 40mg online
generic vardenafil 10mg order plaquenil pills how to buy plaquenil
buy ramipril 5mg online cheap order glimepiride 1mg online cheap buy etoricoxib without a prescription
benicar 10mg brand buy calan 120mg sale buy divalproex generic
order temovate without prescription buspirone pill cordarone buy online
order lanoxin 250 mg generic micardis 80mg over the counter molnupiravir 200 mg brand
medication to stop heart attack buy metoprolol 50mg online cheap medrol 8 mg pills
buy diltiazem pills order zyloprim 100mg sale buy zyloprim pill
toradol over the counter order inderal without prescription order inderal 20mg without prescription
erythromycin price buy nolvadex 20mg order tamoxifen 20mg without prescription
buy budesonide tablets where to buy bimatoprost without a prescription careprost over the counter
topiramate 200mg canada imitrex pills purchase levofloxacin sale
avodart where to buy buy generic ranitidine online meloxicam where to buy
celebrex 200mg pills buy generic zofran for sale buy ondansetron without a prescription
order aldactone buy cheap aldactone purchase valtrex for sale
buy terbinafine generic order lamisil generic trimox 250mg brand
best rated canadian pharmacy
imuran 25mg tablet order imuran 25mg online buy micardis 80mg generic
order prevacid 15mg pills buy lansoprazole 30mg generic pantoprazole 20mg tablet
order avlosulfon generic adalat 30mg us order perindopril 8mg without prescription
online prescriptions
order albenza online albendazole over the counter cheap provera 5mg
pharmacy prices compare
order glucotrol online cheap glipizide over the counter generic betnovate
anafranil 50mg pills purchase anafranil pill prometrium 200mg over the counter
buy epivir pills for sale buy generic lamivudine over the counter buy quinapril 10mg pill
order frumil 5 mg pill order zovirax sale buy acyclovir without prescription
valaciclovir buy online valaciclovir 500mg over the counter ofloxacin 200mg price