位置: 编程技术 - 正文

一篇不错的PHP基础学习笔记(一篇不错的php基础论文)

编辑:rootadmin
1、 PHP片段四种表示形式。 标准tags:<?php ?> short tags:<? ?> 需要在php.ini中设置short _open_tag=on,默认是on asp tags: <% %>需要在php.ini中设置asp_tags=on,默认是off script tags:<script language=”php”></script> 2、 PHP变量及数据类型 1) $variable ,变量以字母、_开始,不能有空格 2) 赋值$variable=value; 3) 弱类型,直接赋值,不需要显示声明数据类型 4) 基本数据类型:Integer,Double,String,Boolean,Object(对象或类),Array(数组) 5) 特殊数据类型:Resourse(对第三方资源(如数据库)的引用),Null(空,未初始化的变量) 3、 操作符 1) 赋值操作符:= 2) 算术操作符:+,-,*,/,%(取模) 3) 连接操作符:. ,无论操作数是什么,都当成String,结果返回String 4) Combined Assignment Operators合计赋值操作符:+=,*=,/=,-=,%=,.= 5) Automatically Incrementing and Decrementing自动增减操作符: (1)$variable+=1 <=>$variable++;$variable-=1 <=>$variable-,跟c语言一样,先做其他操作,后++或- (2)++$variable,-$variable,先++或-,再做其他操作 6) 比较操作符:= =(左边等于右边),!=(左边不等于右边),= = =(左边等于右边,且数据类型相同),>=,>,<,<= 7) 逻辑操作符:|| ó or,&&óand,xor(当左右两边有且只有一个是true,返回true),! 4、 注释: 单行注释:// ,# 多行注释:/* */ 5、 每个语句以;号结尾,与java相同 6、 定义常量:define(“CONSTANS_NAME”,value) 7、 打印语句:print,与c语言相同 8、 流程控制语句 1) if语句: (1)if(expression) { //code to excute if expression evaluates to true } (2)if(expression) { } else { } (3)if(expression1) { } elseif(expression2) { } else { } 2) swich语句 switch ( expression ) { case result // execute this if expression results in result1 break; case result // execute this if expression results in result2 break; default: // execute this if no break statement // has been encountered hitherto } 3) ?操作符: ( expression )?returned_if_expression_is_true:returned_if_expression_is_false; 4) while语句: (1) while ( expression ) { // do something } (2)do { // code to be executed } while ( expression ); 5) for语句: for ( initialization expression; test expression; modification expression ) { // code to be executed } 6) break;continue 9、 编写函数 1) 定义函数: function function_name($argument1,$argument2,……) //形参 { //function code here; } 2) 函数调用 function_name($argument1,$argument2,……); //形参 3) 动态函数调用(Dynamic Function Calls): <html> <head> <title>Listing 6.5</title> </head> <body> <?php function sayHello() { //定义函数sayHello print "hello<br>"; } $function_holder = "sayHello"; //将函数名赋值给变量$function_holder $function_holder(); //变量$function_holder成为函数sayHello的引用,调用$function_holder()相当于调用sayHello ?> </body> </html> 4) 变量作用域: 全局变量: <html> <head> <title>Listing 6.8</title> </head> <body> <?php $life=; function meaningOfLife() { global $life; /*在此处重新声明$life为全局变量,在函数内部访问全局变量必须这样,如果在函数内改变变量的值,将在所有代码片段改变*/ print "The meaning of life is $life<br>"; } meaningOfLife(); ?> </body> </html> 5) 使用static <html> <head> <title>Listing 6.</title> </head> <body> <?php function numberedHeading( $txt ) { static $num_of_calls = 0; $num_of_calls++; print "<h1>$num_of_calls. $txt</h1>"; } numberedHeading("Widgets"); //第一次调用时,打印$num_of_calls值为1 print("We build a fine range of widgets<p>"); numberedHeading("Doodads"); /*第一次调用时,打印$num_of_calls值为2,因为变量是static型的,static型是常驻内存的*/ print("Finest in the world<p>"); ?> </body> </html> 6) 传值(value)和传址(reference): 传值:function function_name($argument) <html> <head> <title>Listing 6.</title> </head> <body> <?php function addFive( $num ) { $num += 5; } $orignum = ; addFive( &$orignum ); print( $orignum ); ?> </body> </html> 结果: 传址:funciton function_name(&$argument) <html> <head> <title>Listing 6.</title> </head> <body> <?php function addFive( &$num ) { $num += 5; /*传递过来的是变量$num的引用,因此改变形参$num的值就是真正改变变量$orignum物理内存中保存的值*/ } $orignum = ; addFive( $orignum ); print( $orignum ); ?> </body> </html> 结果: 7) 创建匿名函数:create_function(‘string1','string2'); create_function是PHP内建函数,专门用于创建匿名函数,接受两个string型参数,第一个是参数列表,第二个是函数的主体 <html> <head> <title>Listing 6.</title> </head> <body> <?php $my_anon = create_function( '$a, $b', 'return $a+$b;' ); print $my_anon( 3, 9 ); // prints ?> </body> </html> 8) 判断函数是否存在:function_exists(function_name),参数为函数名 、 用PHP连接MySQL 1) 连接:&conn=mysql_connect("localhost", "joeuser", "somepass"); 2) 关闭连接:mysql_close($conn); 3) 数据库与连接建立联系:mysql_select_db(database name, connection index); 4) 将SQL语句给MySQL执行:$result = mysql_query($sql, $conn); //增删改查都是这句 5) 检索数据:返回记录数:$number_of_rows = mysql_num_rows($result); 将记录放入数组:$newArray = mysql_fetch_array($result); 例子: <?php // open the connection $conn = mysql_connect("localhost", "joeuser", "somepass"); // pick the database to use mysql_select_db("testDB",$conn); // create the SQL statement $sql = "SELECT * FROM testTable"; // execute the SQL statement $result = mysql_query($sql, $conn) or die(mysql_error()); //go through each row in the result set and display data while ($newArray = mysql_fetch_array($result)) { // give a name to the fields $id = $newArray['id']; $testField = $newArray['testField']; //echo the results onscreen echo "The ID is $id and the text is $testField <br>"; } ?> 、 接受表单元素:$_POST[表单元素名], 如<input type=text name=user>ó$_POST[user] 接受url中queryString中值(GET方式):$_GET[queryString] 、转向其他页面:header("Location: 、字符串操作: 1)explode(“-”,str)óJava中的splite 2)str_replace($str1,$str2,$str3) =>$str1要查找的字符串,$str2用来替换的字符串,$str3从这个字符串开始查找替换 3)substr_replace: 、session: 1)打开session:session_start(); //也可以在php.ini设置session_auto_start=1,不必再每个script都写这句,但是默认为0,则必须要写。 2)给session赋值:$_SESSION[session_variable_name]=$variable; 3)访问session:$variable =$_SESSION[session_variable_name]; 4)销毁session:session_destroy(); 、显示分类的完整例子: <?php //connect to database $conn = mysql_connect("localhost", "joeuser", "somepass") or die(mysql_error()); mysql_select_db("testDB",$conn) or die(mysql_error()); $display_block = "<h1>My Categories</h1> <P>Select a category to see its items.</p>"; //show categories first $get_cats = "select id, cat_title, cat_desc from store_categories order by cat_title"; $get_cats_res = mysql_query($get_cats) or die(mysql_error()); if (mysql_num_rows($get_cats_res) < 1) { //如果返回记录行数小于1,则说明没有分类 $display_block = "<P><em>Sorry, no categories to browse.</em></p>"; } else { while ($cats = mysql_fetch_array($get_cats_res)) { //将记录放入变量$cats中 $cat_id = $cats[id]; $cat_title = strtoupper(stripslashes($cats[cat_title])); $cat_desc = stripslashes($cats[cat_desc]); $display_block .= "<p><strong><a href="$_SERVER[PHP_SELF][U1] ?cat_id=$cat_id">$cat_title</a></strong>//点击此url,刷新本页,第行读取cat_id,显示相应分类的条目 <br>$cat_desc</p>"; if ($_GET[cat_id] == $cat_id) { //选择一个分类,看下面的条目 //get items $get_items = "select id, item_title, item_price from store_items where cat_id = $cat_id order by item_title"; $get_items_res = mysql_query($get_items) or die(mysql_error()); if (mysql_num_rows($get_items_res) < 1) { $display_block = "<P><em>Sorry, no items in this category.</em></p>"; } else { $display_block .= "<ul>"; while ($items = mysql_fetch_array($get_items_res)) { $item_id = $items[id]; $item_title = stripslashes($items[item_title]); $item_price = $items[item_price]; $display_block .= "<li><a href="showitem.php?item_id=$item_id">$item_title</a> </strong> ($$item_price)"; [U2] } $display_block .= "</ul>"; } } } } ?> <HTML> <HEAD> <TITLE>My Categories</TITLE> </HEAD> <BODY> <? print $display_block; ?> </BODY> </HTML> 、PHP连接Access: <? $dbc=new com("adodb.connection"); $dbc->open("driver=microsoft access driver (*.mdb);dbq=c:member.mdb"); $rs=$dbc->execute("select * from tablename"); $i=0; while (!$rs->eof){ $i+=1 $fld0=$rs->fields["UserName"]; $fld0=$rs->fields["Password"]; .... echo "$fld0->value $fld1->value ...."; $rs->movenext(); } $rs->close(); ?>

推荐整理分享一篇不错的PHP基础学习笔记(一篇不错的php基础论文),希望有所帮助,仅作参考,欢迎阅读内容。

一篇不错的PHP基础学习笔记(一篇不错的php基础论文)

文章相关热门搜索词:基础php,一篇不错的php基础文件,一篇不错的php基础书,php0基础,php基础教程,一篇不错的php基础论文,基础php,一篇不错的php基础论文,内容如对您有帮助,希望把文章链接给更多的朋友!

PHP5中的this,self和parent关键字详解教程 首先我们来明白上面三个关键字:this,self,parent,从字面上比较好理解,是指这,自己,父亲,呵呵,比较好玩了,我们先建立几个概念,这三个关键字分别是用在什

phpMyAdmin 安装教程全攻略 管理MYSQL数据库的最好工具是PHPmyAdmin,现在最新版本是phpMyAdmin2.9.0.2,这是一个国际上开源的软件,一直在更新版本,你可以从

PHP入门速成教程 PHP是一种用于创建动态WEB页面的服务端脚本语言。如同ASP和ColdFusion,用户可以混合使用PHP和HTML编写WEB页面,当访问者浏览到该页面时,服务端会首先对

标签: 一篇不错的php基础论文

本文链接地址:https://www.jiuchutong.com/biancheng/276726.html 转载请保留说明!

上一篇:PHP_MySQL教程-第三天 基本函数第1/2页(php语言之mysql操作)

下一篇:PHP5中的this,self和parent关键字详解教程(php中this和self的区别)

  • 每月进项税额怎么算
  • 汇算清缴时房企毛利额有差异如何调整
  • 社保税局代缴
  • 投资收益免征企业所得税
  • 个体工商户需要报税吗
  • 小规模出租不动产免税吗
  • 投资盈利后可以买股票吗
  • 增值税一般纳税人证明怎么查询
  • 无形资产报废的例题
  • 润滑油交消费税税率
  • 以土地出资土地增值税
  • 股权变更怎么缴税
  • app 开发公司的账务处理
  • 自建厂房可以不办理房产证吗
  • 拨款和支出的区别
  • 收到运输发票需要开票吗
  • 风险纳税人怎么查询
  • 哪些出口业务不能做
  • 增值税记账流程
  • 用于当年免征的增值税
  • 集团公司奖励发放遵循什么原则
  • 持有至到期投资在资产负债表怎么填
  • 个人独资企业的特点
  • 消费税的纳税地点在哪里
  • 所得税申报填写
  • 出口视同内销如何申报?
  • 已开票不确认收入未收款怎么做账
  • 工业废弃物处理方式
  • 小规模纳税人采购商品时有可能涉及的会计科目有
  • 减免税额科目有没有余额
  • 其他业务支出包括的内容
  • 代理报关费会计怎么做账
  • 留存收益怎么计算,它属于企业的什么资金?
  • 企业收到分红款是免税收入吗
  • 息税前利润和税前净利润的关系
  • 合同违约金可以全额扣除吗
  • php 读取大excel
  • 投标须知所包括的内容有哪些
  • 购买方未抵扣,销售方申请红字
  • 补提所得税费用可以直接计入当期
  • 网页视频不显示画面
  • 工会账户必须是专用账户吗
  • 其他科技推广服务业可以加计扣除吗
  • 公司租赁个人车辆怎么开发票
  • 外贸企业上年的税收
  • 如何测试php
  • 国税申报系统操作流程
  • 城镇土地使用税征收标准及计算方法
  • 帝国cms什么语言
  • mysql创建存储过程sql语句
  • 开增值税发票规格是否可以不用填?
  • 第二季度所得税表中研发费用
  • 金融资产是分为哪三分类?
  • 主办会计的工作内容和职责
  • 生产工人工资结算表格模板
  • 商品损耗科目
  • 红冲发票如何做账
  • 企业哪些部门
  • 暂估入库结转成本
  • 结算金额和付款金额
  • sql语句重复
  • ubuntu 装系统
  • ubuntu搜索已安装软件
  • wrsvn.exe是什么
  • 注册表干嘛用
  • 删除xp本地保存的视频
  • win10每周更新
  • win7系统在哪里看显卡
  • win10网速特别慢
  • linux mv命令的用法
  • bootstrap怎么用
  • linux中shell脚本编写
  • vue组件的使用步骤
  • javascript如何输出变量
  • python整理表格不用入门
  • 浅析科学发展观的核心立场
  • php和python有什么区别
  • python time模块日期运算
  • 车船税代收有发票吗
  • 云南 过年
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设