




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、ObjectivesIn this chapter, you will learn: To understand PHP data types, operators, arrays and control structures. To understand string processing and regular expressions in PHP. To construct programs that interact with MySQL databases.ClientServerJavaScript, VBScriptPHP, ASP, JSPObjectivesIntroduct
2、ion for PHPPrintOperatorProcessingConditional statementLoopUseful functionString functionMySQL connectionIntroductionPHPPHP: Hypertext PreprocessorOriginally called “Personal Home Page Tools”1997, PHP3Popular server-side scripting technologyOpen-sourceAnyone may view, modify and redistribute source
3、codeSupported freely by communityPlatform independentPHPEmbedded directly into XHTML documentsWithout having to use multiple print statements (CGI)Basic applicationScripting delimitersMust enclose all script codeVariables preceded by $ $ symbolCase-sensitive (有大小寫之分的)End statements with semicolon “;
4、”Comments/ for single line/* */ for multilineFilenames end with .php by convention7 PHP hello worldweb page titleOutput: hello world!By PHPhttp:/localhost/php_practice/helloworld.php PrintOutput stringecho “test”; / print “test”; 雙引號可以代換變數$a = “John;echo “I am $a”;echo “I am “.$a;Output:I am John單引號
5、 裏面所包含所有字串都會直接顯示,不會代換echo I am $a;echo I am $a;http:/localhost/php_practice/practice_print.php operators算術運算子算術運算子 運算子運算子範例範例用途用途+$a + $b$a 和 $b 的和。-$a - $b$a 和 $b 的差。*$a * $b$a 和 $b 的乘積。/$a / $b$a 除以 $b 的商。%$a % $b$a 除以 $b 的餘數。基本的指定運算符就是”=“。並不稱做”等於”,實際上意味著把右邊運算式的值指定給左運算數。例如:$a = $a + 2;指定運算子指定運算子位元
6、運算子位元運算子 範例範例名稱名稱結果結果$a & $bAnd(且)將在 $a 和 $b 中都為 1 的位設為 1。$a | $bOr(或)將在 $a 或者 $b 中為 1 的位設為 1。$a $bXor(互斥)將在 $a 和 $b 中不同的位設為 1。 $aNot(補數)將 $a 中為 0 的位設為 1,反之亦然。$a $bShift right(右移)將 $a 中的位向右移動 $b 次(每一次移動都表示“除以 2”)。範例範例名稱名稱解釋解釋$a = $b等於TRUE,如果 $a 等於 $b。$a = $b全等TRUE,如果 $a 等於 $b,並且它們的類型也相同。(PHP 4 o
7、nly)$a != $b不等TRUE,如果 $a 不等於 $b。$a $b不等TRUE,如果 $a 不等於 $b。$a != $b非全等TRUE,如果 $a 不等於 $b,或者它們的類型不同。(PHP 4 only)$a $b大於TRUE,如果 $a 大於 $b。$a = $b大於等於TRUE,如果 $a 大於或者等於 $b。比較運算子比較運算子執行運算子執行運算子?php $output = dir; echo “ $output ; ? PHP 支持一個執行運算符:反引號 . 。注意這不是單引號!PHP 將嘗試將反引號中的內容作為shell命令來執行,並將其輸出資訊返回(例如,可以賦給一個
8、變數而不是簡單地丟棄到標準輸出)。 加一減一運算子加一減一運算子範例範例名稱名稱解釋解釋+$a前加$a 的值加一,然後返回 $a。$a+後加返回 $a,然後將 $a 的值加一。-$a前減$a 的值減一, 然後返回 $a。$a-後減返回 $a,然後將 $a 的值減一。邏輯運算子邏輯運算子範例範例名稱名稱解釋解釋$a and $bAnd(邏輯與)TRUE,如果 $a 與 $b 都為 TRUE。$a or $bOr(邏輯或)TRUE,如果 $a 或 $b 任一為 TRUE。$a xor $bXor(邏輯互斥)TRUE,如果 $a 或 $b 任一為 TRUE,但不同時是。! $aNot(邏輯非)TRU
9、E,如果 $a 不為 TRUE。$a & $bAnd(邏輯與)TRUE,如果 $a 與 $b 都為 TRUE。$a | $bOr(邏輯或)TRUE,如果 $a 或 $b 任一為 TRUE。Variable (con.)Practice 1.$a= 4;$b= 6;$c= $a + $b;$a+;$b=$b%2;$c= $a + $b;http:/localhost/php_practice/practice_variable_1.phpPractice 2.Please show me the “dir” result in command mode.http:/localhost/p
10、hp_practice/practice_variable_2.phpConditional statementif (condition) statement; if (condition) statement1; else statement2; $a = 123;if($a = = 123)echo A= $a;Print : A= 123 $a = 123;if($a 100)echo A 100;Print : A 123Conditional statement(con.)if ( condition 1) statement 1; elseif (condition 2) sta
11、tement 2; else statement 3; if ($a 100)echo A 100 & $a 100 and A 200;Print : A 100 and A 200Conditional statement(con.)switch ( switch condition ) case value 1 : statement 1; break; case value 2 : statement 2; break; . default : statement n; break;$a = 2;switch ($a)case 1;echo 冠軍;break;case 2;ec
12、ho 亞軍;break;case 3;echo 季軍; break;Print : 亞軍亞軍Take off those “break”http:/localhost/php_practice/practice_switch.php Loopwhile ( condition ) statement; do statement; while ( condition)for (start; end; step) statement; $a=1;while ($a10)echo $a;$a+;$a=1;doecho $a;$a+; while ($a10)For($a=1;$a10;$a+)ech
13、o $a;Loopcontinue: causes the iteration to be skipped.break: causes the loop to stop and program execution to begin at the statement immediately following the loop. Print : 1 3 5 7 9Print : 2 4 6 8http:/localhost/php_practice/practice_continue.php String processingstrlenReturns the length of the giv
14、en string .int strlen(string str);substrReturns the portion of string specified by the start and length parameters.string substr(string string, int start, int length);strip_tagsThis function tries to return a string with all HTML and PHP tags stripped from a given str .string strip_tags(string str);
15、String processing /php%20bible/ltrimStrip whitespace (or other characters) from the beginning of a string. string ltrim(string str);trimThis function returns a string with whitespace stripped from the beginning and end of str.trim() will strip these characters: (ASCII 32 (0 x20), an
16、 ordinary space. t (ASCII 9 (0 x09), a tab. n (ASCII 10 (0 x0A), a new line (line feed). r (ASCII 13 (0 x0D), a carriage return. 0 (ASCII 0 (0 x00), the NUL-byte. x0B (ASCII 11 (0 x0B), a vertical tab. string trim(string str);Practice.$a = “atacgatcgaagagatatatacgcatc”;print $a lengthPrint the “atac
17、gatcgaagagatatatacgcatc”;http:/localhost/php_practice/practice_string.phpFrame姓名: $name = $_POSTname; Output: MySQL connectionmysql_connectOpens or reuses a connection to a MySQL server. mysql_connect(address, name, password);Examplemysql_connect(localhost,root,);mysql_select_dbSelect a MySQL databa
18、semysql_select_db(“database name”);Examplemysql_select_db(“sequence”);MySQL connection(con.)mysql_querySend a MySQL querymysql_query(“sql query”);example$SQL = “select * from subject”;$result = mysql_query(SQL);mysql_fetch_rowGet a result row as an enumerated arrayExample:while($row = mysql_fetch_row($result) for($i=0;$icount($row);$i+ ) echo $row$i.“|; MySQL connection(con.)mysql_fetch_arrayFetch a result row as an associative array, a numeric array, or bothExample:$total=mysql_num_rows($result);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 城镇污水管网建设项目安全管理方案(参考模板)
- xx河流排水防涝设施建设项目数字化方案(范文)
- 城镇污水管网建设项目申请报告(模板范文)
- 乡村振兴战略下能源电力行业面临的挑战及对策
- 物流与供应链管理教案
- 五年级学期学习计划(34篇)
- 2025年光学纤维面板系列项目发展计划
- 五年级科学上册教案 - 5《身体的“联络员”》 教科版
- 中暑现场应急处置方案
- 2025年大流量罗茨鼓风机项目发展计划
- 检查检验结果互认工作管理制度
- 硬膜外血肿的护理常规
- 光伏电站安全生产管理制度汇编
- 农村小学生科技活动方案
- 电脑设备报废管理制度
- 2025年北京高考物理试卷真题(含答案解析)
- 英语教学课件Unit 6 Useful numbers课件6
- GB/T 45823-2025光伏单晶硅生长用石英坩埚高纯内层砂
- 2025至2030中国建设工程质量检测产业市场深度调研及发展趋势与投资报告
- 胸痛医疗质控中心2025年工作计划
- 2025至2030年中国糖精钠行业市场运行态势及发展战略研究报告
评论
0/150
提交评论