学习网站:http://www.w3school.com.cn/php/index.asp
最新中文php手册下载:http://cn2.php.net/distributions/manual/php_enhanced_zh.chm
开始使用写php的时候,里面的php代码不解释,直接按原样输出了,我就很纳闷呀,用utf-8编码能解释,就是中文乱码,用unicode编码中文件不乱码了,就是php不解释,开始以为是 php 出问题呢,后来想到了页面被浏览器显示的问题。
解决方法:
文件保存为utf-8,php就能解释了,为了不乱码要在 head 中加入下面两句话,这下又能解释php又不乱码了,ok :
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
<meta http-equiv=X-UA-Compatible content=IE=EmulateIE7>
呵呵,附上基础的练习代码:
<html> <head> <meta http-equiv=Content-Type content="text/html;charset=utf-8"><meta http-equiv=X-UA-Compatible content=IE=EmulateIE7> <title>php测试首页</title> <style> <!-- Hide style for old browsers BODY {font-family: MS Sans Serif;font-size="10"} .headd { font-family: Helvetica,Verdana ; font-size: 13pt; text-decoration: none; } .app { font-family: MS Sans Serif ; font-size: 10pt; text-decoration: none; } A:link {text-decoration: none; color: #0000FF} A:visited {text-decoration: none; color: #0000FF} A:hover {text-decoration: none; color: #FF0000} A:active {text-decoration: none; color: #FF0000} --> </style> </head> <body bgcolor="#FFFFFF"> <div align="left"> <? $txt = "Hello World!"; $number = 16; echo "你好呀<br/>"; $isConn=true; $conn=mysql_connect("localhost","root","123456");//连接数据库测试 if($isConn && $conn)//if...else 判断 { echo " 连接成功!"; } elseif($isConn==false) { echo " 不需要连接!"; } else { echo " 连接失败!"; } $pos=strpos($txt,"world");//找字符串位置,找不到返回false if($pos==false) $pos=-1; echo "<br/> ".$txt." ".$number;//.号为字符串连接 echo "<br/> ".strlen($txt)." ".strlen("你good");//字符串长度 echo "<br/> ".$pos; echo "<br/> ".md5($txt);//md5加密 echo "<br/> ".html_entity_decode(" <br/> <font>1234</font>");//html解码 echo "<br/> ".htmlentities("<br/> <font>1234</font>");//html编码 echo "<br/> "; switch ($number)//switch语句判断 { case 1: echo "Number 1"; break; case 2: echo "Number 2"; break; case 3: echo "Number 3"; break; default: echo "No number between 1 and 3,is:".$number; } $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34"; echo "<br/> Quagmire is " . $ages['Quagmire'] . " years old."; $arr=array("one", "two", "three"); echo "<br/> for: "; $arrlen=count($arr);//计算数组长度 for ($i=0; $i<$arrlen; $i++)//for语法 { echo $arr[$i]." ;"; } echo "<br/> foreach: "; foreach ($arr as $value)//foreach语法 { echo "Value: " . $value . ";"; } function copyRight()//函数 { echo "power by pkm"; } function myadd($num1,$num2)//带参数的函数 { return $num1+$num2; } echo "<br/> copy right:"; copyRight();//调用函数 echo "<br/> 5 + 4 is ".myadd(5,4)."."; /* $name_post=$_POST["name"];//获取post提交的数据 $age_post=$_POST["age"]; $name_get=$_GET["name"];//获取get提交的数据 $age_get=$_GET["age"]; if($name_post==null) { $name_post=$name_get; $age_post=$age_get; } */ $name_post=$_REQUEST["name"];//获取post或get提交的数据 $age_post=$_REQUEST["age"]; ?> </div> <div align="left"> <form action="" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" value="post提交" /> </form> <form action="" method="get"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" value="get提交" /> </form> <br/> Welcome <?php echo $name_post; ?>.<br /> You are <?php echo $age_post; ?> years old. </div> </body> </html>