php学习笔记

=========================================================
http://e-learning.51cto.com/video/14500
=========================================================
访问表单变量
<metahttp-equiv="Content-Type" content="text/html;charset=gbk">
<form method="post" action="Demo11.php">
    姓名:<input type="text" name="username" value="song"/>
          <input type="submit" value="提交"/>
</form>
=======================================================================
Demo11.php
<?php
    $username=$_post['username']
    echo "这个学生是:".$username
    
?>
===========字符串的插入======================================
双引号提供了最大的灵活性,原因是变量和转移序列都会得到相应的解析
<?php
$userName="SONG";
echo "his name is $uerName"
echo"<br/>"
echo "他的名字叫$userName,他19岁了,已经长大成人了!";
echo "他的名字叫$userName"."他19岁了,已经长大成人了!";
echo "<br/>"
echo "虽然他的QQ号有 很多女生,\n但一个都不属于他";   // \n换行符(编辑器)

?>
单引号会按照声明的原样解释,解析字符串时,变量和转义序列都不会进行解析。
\t   制表符
\n    换行符
\r    回车
=====================操作符===============
<?php
$a=5;
$b=6;

#$c=$a+$b;
#echo $c;

$a+=$b; //a=a+b;
echo $a;
?>
===   恒等  数值与类型相等
&& 与同时满足时为真
||  满足一个为真
//开发中最好将错误暴露出来
$a=@(100/0);    //错误一致操作符
为了避免优先级混乱 可以加括号
================================操作符和控制结构=========================================
<?php
$userAge = 19;
if($userAge>14){
echo "成年了";
}elseif($userAge>25){
echo '可以了!'
}elseif($userAge>30){
echo '可以回家了'
}
==================================switch语句==============================
<?php
$weekday=1;
switch ($weekday){
case 1:
    echo '今天星期一';
case 2:
    echo '今天星期二';
    }
    break;
    default: 
    echo '无聊在家';
?>              //块语句
==============================while======================
<?php

$a=10;
while($>0){
echo $a;
    $--;
    echo'<br/>';
    }
?>
========================for=================================
<?php\
for($a=10;a>0;$a--){
echo $a;
echo '<br/>';
}
echo "结束了"
?>
====================do while===============================
<?php
$a=10;
do{
echo $a;
$a--;
echo '<br/>';
}while($a>0)
?>
=====================================break======================
<?php
for ($i = i;$i<=10;$i++){
if($i==5){
break;     //中途退出当前循环,后面会执行       
}            continue //退出当前本次的循环 继续循环
echo $i.'<br/>';
}
?>
=======================数学运算===================================
<?php
$a='5';
$b=7+$a;
echo $b;                //a无法转换为数字
?>
--------------------------
$a='abc';
echo is_numeric($a);                   //检测是否为数字或数字字符串
-------------------------
<php?
if(is_int(5){
echo 'a是一个整数';
}else{
echo 'a不是一个整数';
}
?>
=============================随机数======mt_rand----(speed)=================================
rand   产生随机整数 
<?php
//echo  rand(0,10);
//echo mt_rand(0,100)
echo   getrandmax();   //最大随机值
?>
----------------------------format--------------------------------------

<?php
$i=1234;
$b = number_format($i,2,".",",");          //小数位保留两位      .小数分割
echo $b;
>
abs()   绝对值
floor ()舍去法取整
ceil()进一法取整
round()四舍五入
pow(2,2)   2的2次方
bcadd()  高精度

---------------------10-----数组----------------------------------
一组有某种共同特性的元素
<?php
$usernaema=array('李彦宏','周宏伟','马云','俞敏洪','李开复');
echo $userName[2];
?>
-------------------------------------------------------------------
print_r($userName)    //变量数值
<?php
$uerName=range(1,10)
print_r($uerName);
?>
----------------------------
$letters = range('a,z');
print_r($letters);
---------------------
$username[5]='李艳辉'      //改变数组的值
echo $username
============================
<?php
$username= array('李彦宏','周宏伟','马云','俞敏洪','李开复');
for($i=0;$i<count($usernaem);$i++){
echo $i.---.$username[$i];
echo'<br/>';
}

?>
===============================================
foreach  //不需要考虑key   只能用于数组遍历
foreach($username as $key=>$value){
echo  $value.''<br/>
}
---------------------
if(is_array($username)){
foreach($username as $key=> $value){
echo $key.'---'.$value'<br/>';
    } 
}else{

echo $username;
}
?>
==============================数组==============================================================
<?php
//如果不去声明key
$username= array(''baiud'=>'李彦宏','taobao'=>'马云','xindongfang'=>'俞敏洪');
//自定义键数组
print_r($username)
echo $username['baidu'];   //通过键去打印

?>
----------------------add-----------
<?php
$userage=array('吴起'=>19);
echo $userage['吴起'];
//追加数组
$userage['李艳辉']=23;
$userage['马化腾']=27;
//echo $userage['李艳辉'];
print_r($userage)
?>
-------------------add-----------------
<?php
$userage['吴起']=19;
echo $userage['吴起'];
//追加数组
$userage['李艳辉']=23;
$userage['马化腾']=27;
//echo $userage['李艳辉'];
print_r($userage);

//这里无法使用for循环 只能用foreach遍历
foreach($username as $key=>$value){  //一般要打印下标

echo 【$key.'-----'】.$value.'<br/>'
}
?>
------------------each  //返回数组中当前的键----------------------
<?php
//$userage['李艳辉']=23;
//$userage['马化腾']=27;
//$userage['吴起']=19;
$userage=array('吴起'=>12,'李艳辉'=>34,'胡新鹏=>56');
print_r($userage);
//each  ---返回数组中当前的键/值并将数组的指针向前移动一步
//默认情况下,指针是指向第一个
//如果each($userage),那么获取的就是第一个键值对'吴起=>'
//each这个函数返回的是一个数组,
//将第一个键值对获取到,然后包装成一个新数组


echo each($userage);
print_r(each($userage));
//相当于$a=array([0]=>吴起,[1]=>19,[value]=>19,[key]=>吴起)
each($userage);这是第一步,将19,吴起取出,包装成新数组
$a=each($userage);  //这个是第二步了,指针已经下移
echo $a[0];    //will see wuqi
$a=each($userage);
echo $a[1];            //will print 27
echo $a['value'];  
?>
-------------------用each将数组所有元素循环出来-----------------------------
<?php
$userage=array('吴起'=>12,'李艳辉'=>34,'胡新鹏=>56');
//$a=each($userage);
//echo $a[0].'--'.$a['value']'<br/>';
//$a=each($userage);
//echo $a[0].'--'.$a['value']'<br/>';
//$a=each($userage);
//echo $a[0].'--'.$a['value']'<br/>';

//echo !!each($userage);    //说明有数据,有数据,用布尔值得理念就是true,两个感叹号转换为布尔值
//echo !!each($userage);    
//echo !!each($userage);    
//echo !!each($userage);      //第四个为假
  

while(!!each($userage)){                  //!转换为布尔值
echo $a['key'].'---'.$a['value'].'<br/>'
}
?>
-------------------------------------list------------------------------------------------
// 把数组中的值赋给一些变量 
<?php
//$a=array('aaaa','bbbb','cccc','dddd');
print_r($a);
// list把数组中的值赋给一些变量,list 只认识下标   自定义的字符串是无法识别的 只认识 0 1
//list($var1,$var2,$var3,$var4)=$a;    //a的值给  var 1 2 3 4
//echo $var1;  //print aaa
//echo $var2;  //print bbb
---------------------------------
$userage=array('吴起'=>12,'李艳辉'=>34,'胡新鹏=>56');  //无法识别
so
$userage=array('12','34,'56');
list($a,$b,$c)=$userage;
--------------------
$userage=array('吴起'=>12,'李艳辉'=>34,'胡新鹏=>56');
list($name,$age)=$($userage);

echo $name;
echo $age;
----------------------------------------reset----------------------------------------------
$userage=array('吴起'=>12,'李艳辉'=>34,'胡新鹏=>56');
$a = each($userage);  //吴起
echo $a['key'];
$a = each($userage);   //李艳辉
echo $a['key'];
//第三次想取第一条数据 将数组的 指针 调到第一个指针上
//reset 将数组的指针 指向第一单元
rset($userage);
$a=each($userage);     //吴起
echo $a['key'];
each($userage);      //隔一部
each($userage);
$a=each($userage);     //吴起
echo $a['key'];     //胡新鹏
---------------------------------------array_unique-------------------------------------------------------
$userage=array('吴起'=>12,'李艳辉'=>34,'胡新鹏=>56','王瑞键'=>34);
print_r*($userage);
echo '<br/>'
//array_unique        --移除数组中重复的值
//创建了一个新数组,新的ok  旧的不变   

$a=array_unique($userage);
--------------------------array_filp----------------------------------------------------------------------------------
//变换数据中的键和值
$userage=array('吴起'=>12,'李艳辉'=>34,'胡新鹏=>56');
//array_filp 变换数据中的键和值  不改变本体
$newuserage=array_filp($userage);
print_r($newuserage)
----------------------------------------二维表--------数组里的数组------------------------------------------------------
$product=array(
    array("苹果",6,28.8),
    array("猪肉",2,38.8),
    array("饼干",3,48.8),

);
<?php
$product=array(
    array("苹果",6,28.8),         【0】
    array("猪肉",2,38.8),        【1】
    array("饼干",3,48.8),        【2】

);
//print_r($product);
//print_r($product[0]);         array("苹果",6,28.8),
//print_r($profduct[0][0]);           苹果
//print_r($profduct[0][2]);        28.8

echo "|".$profduct[0][0]."|".$profduct[0][1]."|"."$profduct[0][2]."|<br/>";
echo "|".$profduct[1][0]."|".$profduct[1][1]."|"."$profduct[1][2]."|<br/>";
echo "|".$profduct[2][0]."|".$profduct[2][1]."|"."$profduct[2][2]."|<br/>";

//首先求出外面数组的长度
//echo count($product);   3
//求出内数组的长度
//echo count($product[0/1/2]);
for($i=0;$i<count($product);$i++){
    for($j=0;$j<count($product[$i])$j++){
    echo $product[$i][$j].'|';  
    }
//echo $product[$i].'<br/>';                //三个array
echo '<br/>'; 
}
?>
-------------------------------------------------------------------------------

$product=array(
    array('产品名'=>"苹果",'数量'=>6,'价格'=>28.8),         【0】
    array('产品名'=>"猪肉",'数量'=>2,'价格'=>18.8),
    array('产品名'=>"饼干",'数量'=>3,'价格'=>48.8),
    //for($i=0;$i<count($product);$i++){
    //    for($j=0;$j<count($product[$i])$j++){                 不是 0 1 2  
    //    echo $product[$i][$j].'|';  
    //    }
    echo $product[$i].'<br/>';                //三个array
    //echo '<br/>'; 
  --------------------foreach--------------------
  for($i=0;$i<count($product);$i++){
  foreach($product[$i] as $key=>$value){
  echo $key.'--'.value.'|';
  }
  echo '<br/>';
  -------------------list----each----------------------------
for($i=0;$i<count($product);$i++){
while(!!list(key,$value)=each($product[$i])){
echo $key.'---'.$value.'|';
}
echo '<br/>';

}
------------------------sort 排序-----------------------------------------
<?php
$fruit = array('banner','orange','apple');

//没有排序前 是按key 的形式
sort($fruit);
print_r($fruit);          //a b o 
>
----------中文----------
$userage=array('吴起'=>12,'李艳辉'=>34,'胡新鹏=>56');
print_r($userage);
echo'<br/>';
sort($userage);
print_r($userage);                 //中文也可以数字也可以 升序
-------------------sort_string---------------------------
$number=array(2,12);
//按照数字的话,要看整体的大小,按照字符串的话,只看第一位大小
sort($number,sort_string);
print_r($number);
------------asort----------------------------
//原始的键是
$fruit = array('banner','orange','apple');
echo '原始的:';
print_r($fruit);
//保持原始的key的关联
asort($fruit);              //下标不变
echo '<br/>';
----------------ksort-------------------------
$fruit = array('banner','orange','apple');
//按照键名排序
print_r($fruit);        a b c
-----------------------------rsort----------------------------------------------
$number=array(2,34,1,5,88,2,3,667,34);
rsort($number);
print_r($number);
-----------------------------------
<?php
//echo'<img src="image/mm1.jpg">'
$pic=array('mm1.jpg','mm2.jpg','mm3.jpg','mm4.jpg','mm5.jpg',)

//数组进行随机打乱
shuffle($pic);  
//对数组进行反向排序  array_*一般是新数组
array_reverse($pic);


for($i=0;$i<3;$i++){
echo '<img src="image/'.$pic[$i].'" style="margin:10px;"/>';
echo "\n";
}
?>
------------------------------------array_unshift-----------------------------------------------
$username=array("吴起");

函数的返回值将会得到数组的个数

array_unshift($username,'胡新鹏');开头insert
array_unshift($username,'李艳辉');结尾insert
print_r($username);

array_shift($username);    删除开头的元素
----------------------array_rand-------------------
$fruit=array('bannner','orange','apple');
//这个函数用来获取一个数组中的键(key)
//这个参数表明随即获取几个
$a=array_rand($fruit,1);    随即两个
echo $a[1]
echo $fruit[$a];
------------------------------------------------------------------------
$userage=array('吴起','李艳辉','胡新鹏');
//获取指针的当前元素
echo current($username);    //并将指针移到下一位
echo  next($username);
echo reset($username);  指向第一个单元
echo prec($username);    back one
echo sizeof($username)  //数组的个数
-----------------------------------------
$username=array(1,24,4,.6,67.8,8)

print_r(array_count_values($username))    //value出现的个数
------------------------------------------------------------------------
$fruit=array('a'=>'apple','b'=>'banner','c'=>'orange');
//通过标量函数将字符串键(key)设置为变量,然后将值赋给了这个变量

extract($fruit);
echo $a;
echo $b;
echo $c;
-----------------------解析目录basename()-----------------------------------------
//将一个路径赋给变量
$path='C:\EFI\Microsoft\Boot\cs-CZ.php';
echo basename($path);            .后面的文件类型
----------------------------返回目录部分-------------------------------------------
echo dirname($path);     .之前的
echo pathinfo($path)      //创建的是array 
$array_path = pathinfo($path);
echo $array_path[dirname];             //打印出目录
echo $array_path[basename];
------------------------------------------------------------------------------------------
$path="demo2.php";              ../
echo realpath($path);              //真实的路径
-----------------磁盘目录和文件计算------------------
filesize  文件的大小
$path='C:\EFI\Microsoft\Boot\cs-CZ.php';
echo  filesize($path)  //字节  1024
echo  round(filesize($path)/1024,2).kb;
---------------------计算磁盘可用空间-------------------
echo round(disk_free_space('C:')/1024,2).kb;
------------------------------总空间大小-----------------------------
echo round(disk_total_space('C:')/1024,2).kb;
--------------------最后改变的时间------------------
echo fileatime($path);
-------------------格式化一个本地日期-----------------------
date_default_tiemzone_set('Asia/shanghai');
//获取最后的访问时间
echo date('Y-m-d:i:s',fileasize($path));
echo date('Y-m-d:i:s',filecsize($path));      //内容的修改时间  
echo date('Y-m-d:i:s',filemsize($path));      //权限的修改时间
------------------------文件处理------------------------------------------
$fp=fopen("file.txt",'w');    //第一参数为那个文件   w  只写  清空插入第一行  没有文件时 试图创建
$outstring='This  is  a wq!'

fwrite//返回的是资源类型
$outstring="This is a wq! he is 19";
fwrite($fp,$outstring,strlen($outstring));             //最后一位数表示限制的长度   用strlen函数
fclose($fp);

--------------------------------------------------------------------------------------------------------
file_put_counts('file2.txt','this is a wq!');           php5才可以使用
--------------------------------------------写入文件---------------------------------------------------------
$fp=fopen('file.txt','w');
$outputstring='this is wq!\r\n thsi is  19';              //\r\n 可以用文本换行
fwrite($fp,$outputstring,strlen($outputstring));
fclose($fp);
--------------------------
file_put_count('file2.txt','this is wq!\r\n thsi is  19');
------------------------------------------------读出文件---------------------------------------------------------------
a  //追加写
$fp=fopen('file.txt',r)          
fgetc($fp);
echo fgetc($fp);//读出一个字符,指针下移到下一个文件
//fgets                //读出文件的一行
fgets($fp);
echo fgets($fp,2);       2行
fgetss($fp);           //过滤html code
fread($fp,2);                //读取定量字节   2
fpassthru();                        //输出文件指针处的剩余所有依据 本身包含了向浏览器输出的功能  返回的是剩余的总长度
------------------------------file-----------------------------------
//把整个文件读入数组中 按每行来分组
  $array_file=file('path')                     //不需要文件聚丙
 echo array_file=[4]              打印文件的第五行
 -------------readfile----------------------------------------------------------------------
readfile('file.txt');                //将整个文件读出来  自带echo

echo   file_getcontents('file.txt')           //保存到缓冲区 通过echo打印出来
-----------------------------------------feof--------------------------------
//检测文件指针是否为结尾
$fp=open('file.txt','r');
while(!feof($fp)){
echo fgetc($fp);
}
fclose($fp);
----------------------------------file_exists--------------------------
//查看文件是否存在  读取文件时 一定要存在
if (file_exists('file.txt')){
echo 'z执行各种各样的文本读写操作';
}else{
echo '此文件不存在,请管理员创建此文件';
}
--------------------------file_size------------------
echo file_size('file_txt');           //文本大小
//删除文件
unlink('123.txt');
-----------------------------rewind倒回到指针的位置--------------------------------------------------
$fp=open('file.txt','r');
echo  fgetc($fp);              //读出并移到下一个
echo  fgetc($fp); 
rewind($fp);
echo  fgetc($fp);
fclose($fp);
----------------------------------------------ftell-----------------------------------------
$fp=open('file.txt','r');
echo  fgetc($fp);              //读出并移到下一个
echo  fgetc($fp);
rewind($fp);
echo  fgetc($fp);
echo ftell($fp);        //查看指针的位置
   
fclose($fp);
------------------------fseek------------------
//在文件指针中定位
$fp=open('file.txt','r');
echo  ftell($fp);
fseek($fp,22);
echo   ftell($fp);\
fclose($fp);
----------------------flock----------------------------
//文件的锁定
a 表示可以追加 b 表示二进制
flock($fp,LOCK_EX);
echo  fgetc($fp);
flock($fp,LOCK_UN);
-------------------opendir----------------------------------------
//打开目录的指定流
$dir=open('distinct_path');               @ 不让错误暴露出来

while($file=readdir($dir)){

echo $file.'<br/>';


}


closedir('$dir');
----------------------scandir-----------------------------------
打印文件
print_r(scandir('distinct_path'));
--------------------rmdir--------------------
rmdir('wode.txt');
------------------rename----------------------------
//目录和文件都可以改
rename('text.txt','wode.txt');
-----------unlink--------------
unlink('wode.txt');
-=========================================md5=============================================================
//对字符串进行加密
echo  md5('134345');
echo '<br/>';
echo  hha('134345');
--------------------------------------function---------------------
function functionname(){
echo '我是一个五参数无返回的函数';
}
  functionname();
--------------------------------------
function  functionmianji($radiu=10) {
$area = $radius*$radius*pi();
echo '半径为:'.$radius.'的面积为'.$area;
}
functionmianji(20);
----------------------------------------
function  functionmianji($radius) {
$area = $radius*$radius*pi();
return    $area;
//echo '半径为:'.$radius.'的面积为'.$area;
}
//大大提高了灵活性
echo '面积为:'functionmianji(20);
---------------------------------------------------
返回多个值得函数调用,可以通过返回一个数组然后可以使用list()函数构造即可
 function functioninfo($name,$age,$job){
    //$userinfo=array($name,$age,$job);      
    $userinfo[]=$username;        //可以用追加的方式比较常用    
    $userinfo[]=$age;
    $userinfo[]=$job;

    return $userinfo;
 }
 
 //$arr=(functioninfo('吴起',19,'学生'));
 //echo $ARR[0];
 
 //调用函数
 list($name,$age,$job)=functioninfo('吴起',19,'学生');
echo  $name.'今年'.'$age'.岁了,他还是'.$job;
------------------------------引用传参---------------------------------
$price = 50;
$tax = 0.5;

//值传参
function functionprice(&$price,$tax){       //&  引用   if not exists;

$pices=$pices+$pices*$tax;
$tax=$tax*$tax;

echo $price;   //75          //外面和里面没关系
echo '<br/>';
echo $tax;

}
functionprice($price,$tax);  
echo $price;     //50      加取址符为75 开辟新的空间
echo '<br/>';
echo $tax;                       //变量区分大小写,函数不区分大小写
----------------------全局变量--------------------------------------
 $a=5;
 function fa(){
 //global $a;         //全局变量
 //$a=2;
$GLODALS['a']=2;


 }
fa();
//echo $a;
echo $GLOBALS['a'];        //超级全局变量
print_r($GLOBALS);
------------------创建自己的函数库(library)--------------------------------------------
function functionpi(){       

return pi();
}   //会存到函数库
---------------------
这句话 把函数库复制过来了
include 'library/tool.library.php';
echo functionpi();  //3.1492615
---------------------------------函数的引用--------------------------------
include ('demo11.php');          //不存在会警告但是继续执行
include_once ('demo1.php' );      //只能包含一次
require_once('demo1.php' );         //recommand
require('demo11.php');       //不存在直接停掉 $ expose
echo '<strong>这是demo11.php </strong>'
-----------------------------------魔法常量-------------------------------
//—file—
//魔法常量 说白了就是一个值而已
$file=_file_
echo $file;    //当前的文件名
//所以包含文件时 推荐使用
//DIR 取得目录 ,去掉文件名
require(dirname(_FILE_).'demo1.phpo');
----------------------------
_LINE_  //return current  line
echo _LINE_;
----------------
function fff(){
return _FUNCTION_;     //return  current function name
}
fff();
-------------------------字符串的格式化---------------------
echo trim('     php     ');  //清理一下两边的空格  ltrim  rtrim(chop)
---------------\n=><br/>-----------------------
//将字符串作为输入函数,用html中的,<br/>标记 代替字符串中的换行符
echo nl2br("this is a teacher!\n this is a student!");      \n 较多
--------all of string transformate html --------------------------------
$str='<strong>吴起<strong>';
echo htmllentitis($str);  //转换所有字符
htmlspecialchars  //我们只需要转换特殊字符
strip_tags        //去掉标签(strong)
---------------------addslashes-------------------------
$str='this is a teacher. hios a  "lee",\n this is wuqi';
$a= addslashes($str);      //过滤
//对于即将插入数据库的字符串,全部会格式化
//这个a 就是写入数据库的,拿出来的话就会有 \这个符号
echo stripcslashes($a);            //解析
---------------------upper------------------------------
 echo  strtoupper('yse@gmail.com'); //将英文转化为大写
 echo  strtolower('yse@gmail.com');  //lower 
 echo  ucfirst('yse@gmail.com');    //first
 echo  ucwords('yse@gmail.com');    // EVER word’s first
-------------------------------str_pad---------------------------
//填充字符串函数  str_pad
$str = 'Lee';
echo str_pad($str,5.'#',STR_PAD_BOTH(LEFT)).'is good!';    //默认的是后面
-----------------------操作字符串---------------------------------------
explode 一个字符串切割另一个字符串
$email=explode('@','yse@gmail.com');
echo $email;
print_r($email);
---------------------------------------------
//分割完了,我经过一轮筛选,还要重新组合
$arr=array('Lee','Wq','Hxp');
$str=implode('&',$arr);        //连接符为&
echo $str;        
--------------------------------------
$str=" i will be back";
//$arr=explode('',$str);

print_r($arr);
----------切开字符串----------------------
$str=" i,will.be#back";
#tok=strok($str,',.#');
//echo $tok;
while($tok){
echo $tok.'<>';
$tok=strtok(',.#');         //分割符 
}
------------------substr----------------------------
$str='yse@gmail.com';
echo    substr($str,0,1)   中间的 是位数,最后一个取几个
------------------------str_split()---------------------
分解字符串  返回一个数组
//$str=' This is a teacher';
//$str='他是吴起';   //中文不太好取 两个字节
print_r(str_split($str));
----------------------strrev()-------------------------
//字符串会逆序   中文不支持
$str=' This is a teacher';
print_r(strrev($str));
------------------字符串的比较--------------------
==比较字符串是否一致    返回 0 负数  整数  区分大小写
if(strcmp('b','b')==0{    //非自然排序
echo "=="
}  
---------------------
echo strccasecmp('B','b');  //不区分大小写
echo strnatcmp('2','10');    //自然排序  10 大
-----------------strspn-----------------
echo strspn('123','123@qq.com',3,5);   //返回几个字母,第三个开始取五位
echo strlen('thjis');  字符串的长度
echo substr_count('thjis',i);  i出现的次数
-------------------查找替换--------------------------
strstr  开始到结尾的位置
echo strstr('yc60.com@gmail.com','@');
//从指定的字符串输出之后的字符串 不区分大小写
echo stistr('yc60.com@gmail.com','g');
-----------------strchr(别名)-------------------------
//查照某字符串 最先出现的位置
echo    strpos('yc60.com@gmail.com','g'); 从第0开始
---------------------------
//查照某字符串 最后出现的位置
echo    strrpos('yc60.com@gmail.com','g'); 从第0开始
---------------replace-------------------------------
echo str_replace('Lee','W','this is Lee');
str_ireplace
 --------------
 echo substr_replace('yc60.com@gmail.com','&&',0,5);
第一个位置开始 取出五个来 并将它替换成参数2
------------------处理中文字符----------------------------------
中文字符可以是 utf8 gb2312  utf8  
mb_strlen()=>strlen
$str='我是吴起';
echo strlen($str);   /8个
echo mb_strlen($str,'GBK');         //有第二个参数
----------------------------------
echo    substr($str,1,2,'GBK');
echo    mb_substr($str,1,2);
mb_strstr()=>strstr
echo    md_strpos('我是ABC','我',0,'GBK');
------------------------正则表达式----------------------
perl风格解析语言搜索和替换
<?
//尝试着写第一个正则表达式
    //if('a'=='a'){
    //echo '相等';
    
    //else{
    //echo  '不等''
    //}
----------------------------
eg:preg_match('model','string')
第一个参数为模式,第二个为字符串
--------
//匹配和相等是两个概念  模式是一个整体
$mode='/php/';
$string='php';

if(preg_match($mode,$string)){

echo '匹配';        //按照模式来匹配 只要通过模式
}else{
echo '不匹配';
}   
-------------------------------------
正则表达式中的元素
+    匹配任何至少包含一个前导字符串 
*    匹配0个或者多个              
?    匹配包含零个或一个前导字符串
.    匹配任意字符串
{x}    匹配任何包含x个前导字符串
{x,y}    匹配任何包含x到y个前导字符串
--------------------------------------
//$mode='/ph+p/';  前导为h      
//$mode='/ph*p/';   //0个多个  前导字符不能更改
//$mode='/ph?p/';        0或1  多个不行 
//$mode='/ph.p/';       //任意一个字符  
//$mode='/ph.*p/';    //前导任意个或多个
//$mode='/ph{3}p/';         //必须是三个
//$mode='/ph{3,5}p/';        //三到五个 
//$mode='/ph{3,}p/';        //至少 三个 
//$mode='/php$/';        匹配字符串的行尾 
//$mode='/^php/';        开始进行匹配
//$mode='/^php*/';        相当于等于
//$mode='/php|asp/';        匹配左边或者右边
//$mode='/(this) (is)  a teacher/';  分组
//$string='this is  a teacher';
$string='phhhhhhhp';        
if(preg_match($mode,$string)){

echo '匹配';        //按照模式来匹配 只要通过模式
}else{
echo '不匹配';
}   
==============================正则表达式元字符================================
//$mode='/[a-z]/';        任何包含a-z 中的任意一个
//$mode='/[abc]/';         一个 
//$mode='/[a-zA-Z0-9_]/';=======[\w]               [\W]=![\w]
//$mode='/[^abc]/';        //不包含abc的字符串 
\d=[0-9]
\D=[^0-9]
\s    空白字符
\S     不包含
\b      是否到达边界   边界可以为空格
\B    没有到达边界
\+    正则中的特殊字符   +  
//$string='php';
$string='phphhhhhhp';        
if(preg_match($mode,$string)){
echo '匹配';        //按照模式来匹配 只要通过模式
}else{
echo '不匹配';
}
------------------------------修饰符----------------------------------------
//$model='/php/i';    //修饰符一般在外面   i表示不区分大小写   
//$string='PHP';        
    //$model='/php$/';        采用多行识别    
    //$string="This is a php\n this is a god ";    单引号不能转义

//$model='/php/x'        //忽略掉规则模式中的字符
//$string='PHP';
    //$model='/php/A    从开头开始匹配
    //$string='PHP';
U     禁止贪婪

if(preg_match($mode,$string)){
echo '匹配';        //按照模式来匹配 只要通过模式
}else{
echo '不匹配';
}
------------------------------函数的引用--------------------------------------------------
搜索字符串 返回有某个模式的数组
preg_grep()
$language=array('php','asp','jsp','python','ruby');  //蟒蛇语言
找出*.p
$mode='/p$/'
    print_r(preg_grep($mode,$language));
----------------
$mode='/^p/'        php python
print_r(preg_grep($mode,$language));
--------------------------------------------
搜索模式
preg_match('/php/[1-6]','php5')        返回true or false
-----------------------------------
电子邮件的案例
//通过 拆分的方式来分组
$mode='(/[a-zA-Z0-9_\.]{2,255})@([\w-]{1,255}).*([a-z]{2,4})/';
$string='yc60.com@gmail.com';
if(preg_martch($mode,$string)){
echo'电子邮件合法';
}else{
echo '否则就不合法';
}
------------------------------
//匹配全局正则
preg_match_all('/php[1-6]/','php5php6hfregert','$out');
print_r($out);
echo $out[0];   php5
--------------------------------------
定界特殊的字符串
preg_quote(PHP is $150');
---------------------------preg_rplace-------------------------------
搜索替换
第一个为模式 第二个放的是替换的字符串 第三个为字符串
echo   preg_replace('/php[1-6]',"python","this is a php5,this is a php4");  //同时替换
-----------------------------贪婪问题和分组问题-------------------------------------
//贪婪和分组获取案例,ubb
//将[b][/b] 换成<strong>php5</strong>
//.*  表示匹配0个或者多个
//用括号分三组那么第一组为\1,第二组为\2,第三组为\3,只有一组就\1
//第一个问题[b][\b]和最后一组匹配了   所以导致直接结尾了
//贪婪匹配问题  跟踪最近的一个 
$mode='(/\[b\])(.*)([\b/])/U';              []为字符中的
$string='this is a [b]php5[\b],this is a [b]php5[\b]'
$replace='<strong>\2</strong>'      //取回php5

echo preg_replace($mode,$rplace,$string)
---------------------------------------------------
//正则表达式分割
//如果没有[]表示同时满足
print_r(preg_split('/[.@]/,'yc60.com@gmail.com'));  
*注释:posix格式  ereg_
====================日期和时间库=================================
1970 1月1日。。。。。POSIX time  格林威治时间
checkdate    返回值为布尔型 验证格里高里时间  
-----------------------
if(checkdate(7,16,2010)){
echo  '这个日期是有效的';
}else{
echo  '这个日期不是有效的';
}
----------------
date()  第一个是日期和时间的格式化[timestamp] 
//Y 4位数的时间 y是两位数的日期
//M表示 英文的月份缩写,m表示阿拉伯数字的月份
//D 表示 英文的日缩写,m表示阿拉伯数字的日 
echo date('Y-m-d H:i:sa');
-----------------------------
gettimeofday  //取得当前时间 得到一个数组
print_r(gettimeofday());
//"sec"    Unix 纪元的秒数        
//"usec" -微妙数        
//minuteswest 格林威治向西的分钟数
//dsttime   夏令时修正的类型
-----------------表单与验证--------------------------------
header()函数  //重新导向URL 跳转页面
ob_start();
//除非打开缓冲,否则之前不能有任何浏览器输出
header('Location:http://localhost');
----------------------
//字符编码法
ob_start();   //打开缓冲区
echo '123';
header(Content-Type:text/html;charset=gbk';   //设置页面编码
echo '嘿嘿,我是中文!'
------------------------------------------
hidden    input //隐藏框
file         //上传
-----------------html--------demo3--------------------
<form method="post action="demo.php">    //地址栏看不到
姓名:<input  type="text name="uername"/><br/>
<input type="submit" value="提交"/>
<form/>
----------------------------------demo4------------------
$_post  超级全局变量
<?php
//接受表单上的值
//一个值 username
//$_POST['username'];
//echo  $_POST['username'];   //提交之后会显示
//空字符串也是数据也可以赋值给$_post
//isset()验证是否z正常提交是非常有效的 
//目前所说的恶非法提交,是你没有经过表单提交,没有生产全局变量,而不是username

 
if(echo isset($_POST[username])){      
echo "正常提交";}
else{
echo "非法提交";
}
------------------------empty ------
//判断是否为空
if(empty($_POST[username])){       ==基本一样 只能说人家没有填 
echo "正常提交";
}
else{
echo "非法提交"
}
---------------------过滤html-------------------------
<form method="post action="demo.php">    //地址栏看不到
姓名:<input  type="text name="uername"/><br/>
<input type="submit" value="提交"/>
<form/>
-----php---------
if(isset($_POST[username])){          
echo "正常提交"
$username=$_POST['username'];

//为了 页面安全性 
$username=htmlspecialchars($username);
echo $username;
else{
echo "非法提交"
}
---------------------数据有效性---------------------------
if(isset($_POST[username])){          
echo "正常提交"
$username=$_POST['username'];
//有效性
$username=trim($username);
//为了 页面安全性 
$username=htmlspecialchars($username);
if(strlen($username)<2)then{
echo ''用户名不能小于两位;
exit;
}
echo $username
else{
echo "非法提交"
}
--------------------------是否为纯数字----------------
is_numeric
if(isset($_POST[username])){          
echo "正常提交"
$username=$_POST['username'];
//有效性
$username=trim($username);
//为了 页面安全性 
$username=htmlspecialchars($username);
if(strlen($username)<2)then{
echo '用户名不能小于两位';
exit;
}
if(!is_numeric($username))then{
echo '用户名必须是纯数字';
exit;
}
echo $username
else{
echo "非法提交"
}
-----------------------------demo4--------------------------------------
<meta http-equiv="Content-Type" content="text/html";charset=GBK">
<form method="post action="demo5.php">    //地址栏看不到
用户名:<input  type="text" name="uername"/><br/>
密  码:<input type="password" value="password"/><br/>
验证码:<input  type="text" name="code" size="5"/>1234<br/>
邮  件: <input type="text" name="email"/> <br/> 
介  绍:<textarea rows="25"cols="6" name="content"></textarea><br/>
<input  type="submit" value="提交"/><br/>
<form/>
--------------------------------------demo5-------------------------
<?php
header('Content-Type:text-html;charset=gbk');
//是否为demo5提交过来的
//只要是按钮点到这里的 其他超级全局变量都应该存在
//如果 send是存在的,那么就是点过来的,跳回5
if(!isset($_POST['send'])||$_POST[send]!='提交'){
header('Location:Demo5.php');
exit;
}
//第二步接收所有数据
$username=trim($_POST['username']);
$password=$_POST['password'];
$code=trim($_POST['code']);
$email=trim($_POST['email']);
$content=htmlspecialchars(trim($_POST['content']));
//echo $username.$password.$code.$content;
//用户名不能小于两位,不能大于10位;
if(strlen($username)<2||strlen($username)>10){
//使用js跳转
echo "<script>alert('用户名不能小于两位或者大于10位');history.back();</script>"
exit;
}
if(strlen($password)<6{
echo "<script>alert('密码不能小于6位');history.back();</script>"
exit;
}
if(strlen($code)!=4||!is_numeric($code)){
echo "<script>alert('验证码不能小于4位并为纯数字');history.back();</script>"
exit;
}
//验证电子邮件是否合法
if(!preg_match('/([a-zA-Z0-9_\.]{2,255})@([\w-]{1,255}).*([a-z]{2,4})/',$email)){
echo "<script>alert('电子邮件不合法');history.back();</script>"
exit;
}
echo '用户名:'.$username.'<br/>';
echo 'email:'.$email.'<br/>';
echo '个人介绍:'.$content;
?>
--------------------demo1-------------cookie sesion-----------------------------------------------
<form method="get" action="demo2.php">
姓名:<input type="text" name="username"><br/>
<input type="submit" value="提交"/>
</form>
<a href="demo2.php?a=5">Lee</a>       //get方式 可以用超链接来传值
------demo2----------------------
//$_POST['username'];
//如果表单采用的是get那么必须$_GET
$_GET['username'];        不安全
------------------------------cookie sesion---------------------------------------
//客户端存储少量信息,包含登录时的信息
//会话结束时 关闭浏览器就没有了
<?php
setcookie('name','value');             //创建 cookie
//创建一个包含 过期时间的cookie 当前时间戳+秒
//表示未来七天 time()+(7*24*60*60)
setcookie('name','value',time()+(7*24*60*60));

//读取本机的cookie,采用一个超级全局变量$_cookie
//有一个特性,setcookie并不是 及时生成,他会慢一拍 第一次刷新不会获取到 而二次才会真正获取到
echo  $_cookie['name'];
//用变量检测函数来判断cookie是否存在
if(isset($_COOKIE['name'])){
echo $_cookie['name'];
else{
echo '不存在此用户';
}

}
------------------删除cookie-------------------------------------------------------------
setcookie('name','value');  
//setcokie('naem','');
//过期的时间
setcookie('name','value',time()-1);
echo $_cookie['name'];
------------------------------------------cookie----------------------------
html 文件前 处理
不同的浏览器输出的结果不一致
一个浏览器能创建的cookie不能超过三十个并且每个不能超过4    kb 每个web站点能设置的cookie总数不能超过20个
主要限制在客户端
-----------------------------------demo6------会话控制--------------------------------
<form method="post action="demo7.php">    //地址栏看不到
姓名:<input  type="text name="username"/><br/>
<input type="submit" value="提交"/>
<form/>
---------------demo7
如果生成的与指定的相同就完成
if(isset($_POST['username'])&&$_POST['USERNAME']=='Lee'){
setcookie('name','value');
header(Locatin:Demo8.php');
}else{
header(Location:demo6.php);
}
============demo8==
if(isset($_COOKIE['name'])){         //有值
echo '欢迎光临'.$_COOLIE['name'];
}else{
echo '非法登录';
}
---------------------session------demo9----------------
session_start()      //开始会话处理     存在于服务器 存放1440秒 如果没有操作 会自动销毁  php.ini 可以修改
//如果关闭了浏览器 自动销毁
//没有慢一拍 即时性
$_SESSION['NAME']='Lee';
 if(isset($_SESSION['NAME'])){
echo $_SESSION['name'];
}else{
echo '不存在此人';
}

-----------unse------------------
unset($_COOKIE['name']
echo isset($_SESSION['NAME']);
--------demo9-------------------
session_start()  
$_SESSION['NAME']='Lee';
$_SESSION['NAME']='Lee2';
--------demo9-------------------
session_start()  
session_destory();  //销毁所有的session  也慢半拍
     echo $_SESSION['NAME'];
    echo $_SESSION['NAME'];
----------------session案例------------------------
//cookie  会员登录 购物车     不占资源
//session 一般用于后台管理 安全性高
-----------------上传文件-------------------------------------
$_file数组
file_uploads=on|off //php脚本是否可以接受文件上传
max_execution_time=integer   最长的等待时间 mb
memory_limit=integer      设置脚本可以分配到的最大内存 
upload_max_filesize=integer  mb  上传时的最大大小 此指令必须小于post_max_size
upload_tmp_dir=string  上传之前必须放在服务器的一个临时目录 知道文件移动到最终目录位置
past_max_size=integer   post方法最大的接受信息 mb
--------------------------------------------------------------
<form enctype="multipart/form-data" action="upload.php[destinct]" method="post">
//hidden 隐藏字段 隐藏域 超过值时not  file之前  不能超过ini.php
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"/>
上传文件:<input type="file" name="userfile"/>
<input type="submit" value="上传"/>
</form>
--------------------------------------$_files-----------------------------------
<form enctype="multipart/form-data" action="demo2.php[destinct]" method="post">
//hidden 隐藏字段 隐藏域 超过值时not  file之前  不能超过ini.php
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"/>
上传文件:<input type="file" name="userfile"/>
<input type="submit" value="上传"/>
</form>
-------------------demo1------------------
<?php
//接受文件
//$_Files
//print_r($FILES);
//存在但是是空值
[userfile][name]   
[userfile][type]
[userfile][type_size]
?>
-------------上传文件指定目录-----------------
is_uploaded_file() 
move_uploaded_file() 
//is_uploaded_file()
//上传后会存放到临时目录下

define('URL',_file_dirname(_file_).'/uploads');

//设置大小问题
if($FILES['usefile']['size']>MAX_SIZE){

echo  "<script>alert('上传文件不得超过2M');history.back</script>"
exit;
}
//判断目录是否存在
if(!is_dir(URL)){
mkdir(URL,0777);   //最大权限


}

define('MAX_SIZE',2000000);
$fileMimes=array(image/jpeg','image/pjpeg','image/png','image/x-png')
//判断是否为数组中的一种
if(is_array($fileMimes)){
in_array($_FILES['userfile']['type'],$fileMIMES)){
echo  '<script>alert('本站只允许jpg.gif.png图片');history.back</script>'
exit;
  }
}

//1 上传错误
if($_FILES['userfile']['error']>0){
switch($_FILES['userfile']['error']){
case 1:echo  "<script>alert('文件超过约定值');history.back</script>"
break;
case 2:echo  "<script>alert('文件超过约定值');history.back</script>"
break;
case 3:echo  "<script>alert('a little');history.back</script>"
break;
case 4:echo  "<script>alert('null');history.back</script>"
break;
}
exit;
}
             //2 只允许jpg
            if($_FILES['userfile']['type']!="img/jpeg" &&img/ejpg"  ){
            echo  "<script>alert('只允许jpg');history.back</script>"

            exit;
            }

        swith($_FILES['userfile']['type']){
        case 'image/jpeg';  //火狐
        break;
        case 'image/pjpeg';  //IE
        break;
        case 'image/gif';  
        break;
        case 'image/png';  //火狐
        break;
        case 'image/x-png';  //IE
        break;
        default :
        echo  "<script>alert('只允许jpg');history.back</script>"
        }


if(is_uploaded_file($_FILES['userfile'])){
//echo '上传的临时文件已经存在,等待移动中,,'
//move_uploaded_file()将上传文件移动到新位置
//第一个  临时文件的地址 
//第二个  存放文件的地址   //相对路径
    //先判断目录是否存在
//屏蔽警告 加@符号
if(!@move_uploaded_file($_FILES['username']['tmp_name'],URL.$FILES['userfile']['name'])){

echo '<script>alert('移动失败');history.back</script>'

exit;}
}else{
echo '<script>alert('找不到上传的文件');history.back</script>'

exit;}

//全部通过就上传成功了
echo '<script>alert('上传成功');location.href="demo3.php?url=".$_FILES['userfile']['name']."</script>'
demo3打印出源URL
-------------------------demo3--------------------
$url=$_GET['url'];
echo '<img src="'.$url.'">'
//echo '<img src="'$_FILES['userfile']['name']'"/>'    not    发送了 2 
----------------------------------上传文件---------------------------------------------------------------
define('URL',_file_dirname(_file_).'/uploads');
---------------------------动态图像的处理----demo1-----------------------------------------------
GD2库
//创建图像
//设置标图
//背景
//文本
//输出图形
//清理资源

//一般生成的是四种 png jpg jpng jpeg
//image 图像函数 只限于html输出

<?php
//1设置文件mime类型,输出类型  默认的 可以不写
header ('Content-Type:image/png');
//创建一个图形区域,图像背景
//2有两种  资源类型 一般加上@防止出错  imagecreate  imagecreatetruecreate
//这个函数创建了一个图像区域。没有进行填充的时候默认为黑色
$im=imagecreatetruecreate(200,200)    返回的是资源聚丙
//3在空白区图像绘制填充
//填充色换掉,首先要有个颜色填充器
//填充色换掉  imagecolorallocate  --为一副图像分配颜色
$blue =imagecolorallocate($im,0,102,255);  
//imgefill将颜色填充到背景
imagefill($im,0,0,$blue);
//4颜色填充 
$whilte=imagecolorallocate($im,255,255,255); 
//imageline --画一条线段
imageline($im,0,0,200,200,$whilte);
imageline($im,200,0,200,200,$whilte);
//imagestring 绘制文本 聚丙 字体size  x y 
imagestring($im,2,0,0,'Mr.Lee,$whilte);

//5输出图形
imagepng($im)
//6清除所有的资源
//imagedestroy($im)   推荐png
------------------demo2---------------------
header ('Content-Type:text/html;charset=gbk');
echo '<img src="demo1.php" alt="图形" title="图形"/>'
----------------------简单的小案例-----------------------------------
//简单的验证码
//随机数
//因为要实现最简单的字母和数字混搭
//十六进制 0-9 a-f 
//十进制转换为十六进制
//创建一个四位

for($i=0;$<4;$i++){
$nmsg.=dechex(mt_rand(0,15));
}
header('Content-Type:iamge/png');
$im=imagecreatetruecolor(75,25);
$blue=imagecolorallocate($im,0,102,255);
$whilte=imagecolorallocate($im,255,255,255);
imagefill($im,0,0,$blue);
imagestring($im,5,20,5,$nmsg,$white);
imagespng($im);
imagesdestory($img);
--------------加载已有的头像-----------------------
define('_DIR_',dirname(_FILE_).'\\');
header('Content-Type:iamge/png');
//imagecreatefrompng    --从png文件中或url新建一图像
//img载入时可以编辑 加水印
$im=iamgecreatefrompng(_DIR_.'222.png');  //全路径
//魔法常量_FILE_

$whilte=imagecolorallocate($im,255,255,255);
imagestring($img,5,0,0,'www.yc6o.com',$whilte);
imagespng($im);   //输出
imagesdestory($img);  //销毁
-------------------加载已有的系统字体---------------------------
define('_DIR_',dirname(_FILE_).'\\');
header('Content-Type:iamge/png');
$im=iamgecreatefrompng(_DIR_.'222.png'); 
$whilte=imagecolorallocate($im,255,255,255);
//采用系统字体
//字体文件
$font='C:\WINDOWS\FONTS\SIMHEI.TTF';
//字体转换
$text=iconv('gbk','utf-8','小李');
//第二个参数是字体的大小  
//三个 旋转角度
//四五参数是坐标
imagegettftext($im,20,0,30,30,$while,$font,$text)
-----------------------------------微缩图的问题-----------------------------
//<img src="22.png" width="20" heigth="40"/>   //会失真
//容量 大小都变小了
header('Content-Type:iamge/png');
define('_DIR_',dirname(_FILE_).'\\');
//getimagesize  取得图像大小
//获取到了原图的长度和高度
list($width,$height)=getimagesize(_DIR_.'222,png');
$_width=$width*0.4;
$_height*=$height*0.4;
//创建一张新图 
$im=imagecreatetruecolor($width,$heigth);

//下面的工作是载入原图,并复制到新图上去
$_im=imagecreatefrompng(_DIR_.'222.png');
//将原图重新采样到新图上 按0.4的比例输出
//imagecopyresampled  --重新采样 并调整大小
imagecopyresampled($im,$_im,0,0,0,$_width,$_height,$width,$height);


//将新图输出
imagepng($im);
//销毁
imagedestory($im);
imagedestory($_im);
---------jpeg
imagepng($im,null,34);  34 表示清晰度也会改变大小
载入jpg
导出的为png?    ok  
-----------------------------------mysql数据库-------------------------------------------
原子列值(对每一行的为一性)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.16    |
+-----------+
------------------
mysql> select version(),current_date();
+-----------+----------------+
| version() | current_date() |
+-----------+----------------+
| 5.7.16    | 2018-04-24     |
+-----------+----------------+
---------------------------------
char 定长类型   4个字节   性别  密码  速度快
varchar 可变类型 自身长度加1个字节  用户名  
//备注型;
TINYTEXT 字符串,最大长度255个字符串 
TEXT     字符串,最大长度65535个字符;  文章 帖子
MEDIUMTEXT 字符串,最大长度16777215个字符
LONGTEXT   字符串 最大长度4294967295
---------------------------
mysql> select database();
+------------+
| database() |
+------------+
| NULL       |
+------------+
mysql> insert into users (username,sex,birth) values ('Lee','0',now());
-----------------数据库操作-------------
mysql> set names gbk;     //设置字符编码
Query OK, 0 rows affected (0.00 sec)
-------------
mysql> select * from  users order by birth desc;  //倒序
mysql> update users set   username='hang'   where g_id=1;  //更新数据
---------------------MySQL函数------------------------
文本函数
mysql> select concat('son','g') as 'link chars';
+------------+
| link chars |
+------------+
| song       |
+------------+
1 row in set (0.00 sec)
-------------------------------------
mysql> select   length ('song')
    -> ;
+-----------------+
| length ('song') |
+-----------------+
|               4 |
+-----------------+
1 row in set (0.00 sec)
--------------------------------------
select left (colume,x);    列的左边取两个字符;
mysql> select  trim('  24324   ')  as trim;
+-------+
| trim  |
+-------+
| 24324 |
+-------+
1 row in set (0.00 sec)
-----------------
UPPER(COLUMN)  转化为大写
LOWER(COLUMN)  转化为小写
substring(column,start,length)      从column中返回开始start 的length 个字符(索引从0开始)
MD5(column)  把存储的字符串用MD5加密
sha(column)    sha256加密;
-----------------------------
mysql> select SUBSTRING('THIS IS A  TEACHER',2,5);
+-------------------------------------+
| SUBSTRING('THIS IS A  TEACHER',2,5) |
+-------------------------------------+
| HIS I                               |
+-------------------------------------+
1 row in set (0.00 sec)
----------------数字函数------------------------
ABS(X)        返回x的绝对值
CEILING(X)    返回x的值的最大整数
floor(x)    返回x的整数
round(x)    返回x的四舍五入
mod (x)        返回x的余数
rand(x)        返回0-1.0之间的随机数
format(x,y)    返回格式化后的一个小数
sign        返回一个值正数(+1),0,(-1);
sqrt(x)        返回x的平方根
--------------------格式化日期和时间--------------------------
%e    一月中的某天
%d    一月中的某天,两位
%D    带后缀的天
%W    周日的名称        
%T    24小时
%r      12
%p    上午或下午

mysql> select date_format(NOW(),'%Y'); 
+-------------------------+
| date_format(NOW(),'%Y') |
+-------------------------+
| 2018                    |
+-------------------------+
1 row in set (0.00 sec)
mysql> select date_format(NOW(),'%H:%i:%S:%p');
+----------------------------------+
| date_format(NOW(),'%H:%i:%S:%p') |
+----------------------------------+
| 13:42:10:PM                      |
+----------------------------------+
1 row in set (0.00 sec)
------------sql语句-------------------------
mysql> create database school;
mysql> use school;
mysql> create table grade (
    -> id TINYINT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    -> name varchar(20) not null,
    -> email varchar(40),
    -> point tinyint(3) UNSIGNED NOT NULL,
    -> regdate DATETIME NOT NULL,
    -> PRIMARY KEY (id)
    -> );
Query OK, 0 rows affected (0.01 sec)
mysql> insert into grade(name,email,point,regdate) values ('LEE','YC60@EMAIL.COM','88',NOW()); 
Query OK, 1 row affected (0.00 sec)
mysql> insert into grade(name,email,point,regdate) values ('SINA','sina@EMAIL.COM','48',NOW());        
Query OK, 1 row affected (0.01 sec)
mysql> insert into grade(name,email,point,regdate) values ('HAIMEIMEI','HAI@EMAIL.COM','68',NOW());          
Query OK, 1 row affected (0.00 sec)
mysql> insert into grade(name,email,point,regdate) values ('LILEI','lilei@EMAIL.COM','68',NOW());             
Query OK, 1 row affected (0.00 sec)
mysql> insert into grade(name,email,point,regdate) values ('SUO','SUO@EMAIL.COM','88',NOW());           
Query OK, 1 row affected (0.00 sec)
mysql> insert into grade(name,email,point,regdate) values ('JACK',NULL,48,NOW()); 
mysql> SELECT * from grade;
+----+-----------+-----------------+-------+---------------------+
| id | name      | email           | point | regdate             |
+----+-----------+-----------------+-------+---------------------+
|  1 | LEE       | YC60@EMAIL.COM  |    88 | 2018-04-24 14:05:05 |
|  2 | SINA      | sina@EMAIL.COM  |    48 | 2018-04-24 14:08:34 |
|  3 | HAIMEIMEI | HAI@EMAIL.COM   |    68 | 2018-04-24 14:09:14 |
|  4 | LILEI     | lilei@EMAIL.COM |    68 | 2018-04-24 14:09:33 |
|  5 | SUO       | SUO@EMAIL.COM   |    88 | 2018-04-24 14:10:23 |
|  6 | JACK      | NULL            |    48 | 2018-04-24 14:13:05 |
+----+-----------+-----------------+-------+---------------------+
6 rows in set (0.00 sec)
mysql> select id,name,email from grade;
+----+-----------+-----------------+
| id | name      | email           |
+----+-----------+-----------------+
|  1 | LEE       | YC60@EMAIL.COM  |
|  2 | SINA      | sina@EMAIL.COM  |
|  3 | HAIMEIMEI | HAI@EMAIL.COM   |
|  4 | LILEI     | lilei@EMAIL.COM |
|  5 | SUO       | SUO@EMAIL.COM   |
|  6 | JACK      | NULL            |
+----+-----------+-----------------+
6 rows in set (0.00 sec)
mysql> show create table grade;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                      |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| grade | CREATE TABLE `grade` (
  `id` tinyint(2) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `email` varchar(40) DEFAULT NULL,
  `point` tinyint(3) unsigned NOT NULL,
  `regdate` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from  grade  where name='LEE'; 
+----+------+----------------+-------+---------------------+
| id | name | email          | point | regdate             |
+----+------+----------------+-------+---------------------+
|  1 | LEE  | YC60@EMAIL.COM |    88 | 2018-04-24 14:05:05 |
+----+------+----------------+-------+---------------------+
1 row in set (0.00 sec)
---------------------------------------------
mysql> select * from grade where point>80;
+----+------+----------------+-------+---------------------+
| id | name | email          | point | regdate             |
+----+------+----------------+-------+---------------------+
|  1 | LEE  | YC60@EMAIL.COM |    88 | 2018-04-24 14:05:05 |
|  5 | SUO  | SUO@EMAIL.COM  |    88 | 2018-04-24 14:10:23 |
+----+------+----------------+-------+---------------------+
2 rows in set (0.00 sec)
----------------------------------------------
mysql> select * from grade where email is NULL;
+----+------+-------+-------+---------------------+
| id | name | email | point | regdate             |
+----+------+-------+-------+---------------------+
|  6 | JACK | NULL  |    48 | 2018-04-24 14:13:05 |
+----+------+-------+-------+---------------------+
1 row in set (0.00 sec)
-------------------------------------------
mysql> select * from grade where point BETWEEN 70 AND 90;
+----+------+----------------+-------+---------------------+
| id | name | email          | point | regdate             |
+----+------+----------------+-------+---------------------+
|  1 | LEE  | YC60@EMAIL.COM |    88 | 2018-04-24 14:05:05 |
|  5 | SUO  | SUO@EMAIL.COM  |    88 | 2018-04-24 14:10:23 |
+----+------+----------------+-------+---------------------+
2 rows in set (0.00 sec)
---------------------------
mysql> select * from grade where point IN (88,48);
+----+------+----------------+-------+---------------------+
| id | name | email          | point | regdate             |
+----+------+----------------+-------+---------------------+
|  1 | LEE  | YC60@EMAIL.COM |    88 | 2018-04-24 14:05:05 |
|  2 | SINA | sina@EMAIL.COM |    48 | 2018-04-24 14:08:34 |
|  5 | SUO  | SUO@EMAIL.COM  |    88 | 2018-04-24 14:10:23 |
|  6 | JACK | NULL           |    48 | 2018-04-24 14:13:05 |
+----+------+----------------+-------+---------------------+
--------------------------------------------------------
mysql> select * from grade where email like 'SUO%';
+----+------+---------------+-------+---------------------+
| id | name | email         | point | regdate             |
+----+------+---------------+-------+---------------------+
|  5 | SUO  | SUO@EMAIL.COM |    88 | 2018-04-24 14:10:23 |
+----+------+---------------+-------+---------------------+
1 row in set (0.00 sec)
-------------------------------------------------------------------
mysql> UPDATE grade set  email='WODE@QQCOM'  where name='SUO';                
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
-------------
mysql> SELECT * FROM grade limit 3;
----------------------------------
mysql> SELECT * FROM grade order by regdate desc;
+----+-----------+-----------------+-------+---------------------+
| id | name      | email           | point | regdate             |
+----+-----------+-----------------+-------+---------------------+
|  6 | JACK      | NULL            |    48 | 2018-04-24 14:13:05 |
|  5 | SUO       | WODE@QQCOM      |    88 | 2018-04-24 14:10:23 |
|  4 | LILEI     | lilei@EMAIL.COM |    68 | 2018-04-24 14:09:33 |
|  3 | HAIMEIMEI | HAI@EMAIL.COM   |    68 | 2018-04-24 14:09:14 |
|  2 | SINA      | sina@EMAIL.COM  |    48 | 2018-04-24 14:08:34 |
|  1 | LEE       | YC60@EMAIL.COM  |    88 | 2018-04-24 14:05:05 |
+----+-----------+-----------------+-------+---------------------+
6 rows in set (0.00 sec)
------------------------
mysql> SELECT * FROM grade order by point  asc;
+----+-----------+-----------------+-------+---------------------+
| id | name      | email           | point | regdate             |
+----+-----------+-----------------+-------+---------------------+
|  2 | SINA      | sina@EMAIL.COM  |    48 | 2018-04-24 14:08:34 |
|  6 | JACK      | NULL            |    48 | 2018-04-24 14:13:05 |
|  3 | HAIMEIMEI | HAI@EMAIL.COM   |    68 | 2018-04-24 14:09:14 |
|  4 | LILEI     | lilei@EMAIL.COM |    68 | 2018-04-24 14:09:33 |
|  1 | LEE       | YC60@EMAIL.COM  |    88 | 2018-04-24 14:05:05 |
|  5 | SUO       | WODE@QQCOM      |    88 | 2018-04-24 14:10:23 |
+----+-----------+-----------------+-------+---------------------+
-----------------------------------------------------------------------
mysql> delete from  grade where id=1; 
Query OK, 1 row affected (0.00 sec)
mysql> select avg(point) from grade;
-----------------------------------
mysql> select count(*) from grade;      
+----------+
| count(*) |
+----------+
|        5 |
+----------+
-------------------
mysql> select MAX(point) from grade;       
+------------+
| MAX(point) |
+------------+
|         88 |
+------------+
1 row in set (0.01 sec)

mysql> select MIN(point) from grade;  
+------------+
| MIN(point) |
+------------+
|         48 |
+------------+
1 row in set (0.02 sec)

mysql> select SUM(point) from grade;    
+------------+
| SUM(point) |
+------------+
|        320 |
+------------+
1 row in set (0.00 sec)
--------------------------------
mysql> SHOW TABLE STATUS\G;
*************************** 1. row ***************************
           Name: grade
         Engine: InnoDB
        Version: 10
     Row_format: Dynamic
           Rows: 5
 Avg_row_length: 3276
    Data_length: 16384
Max_data_length: 0
   Index_length: 0
      Data_free: 0
 Auto_increment: 7
    Create_time: 2018-04-24 13:59:14
    Update_time: 2018-04-24 14:39:04
     Check_time: NULL
      Collation: latin1_swedish_ci
       Checksum: NULL
 Create_options: 
        Comment: 
1 row in set (0.00 sec)

ERROR: 
No query specified
----------------
mysql> OPTIMIZE TABLE grade;
+--------------+----------+----------+-------------------------------------------------------------------+
| Table        | Op       | Msg_type | Msg_text                                                          |
+--------------+----------+----------+-------------------------------------------------------------------+
| school.grade | optimize | note     | Table does not support optimize, doing recreate + analyze instead |
| school.grade | optimize | status   | OK                                                                |
+--------------+----------+----------+-------------------------------------------------------------------+
2 rows in set (0.04 sec)
清除缓存
----------mysqladmin-------------------------------------
-------------------mysql数据库操作----------------------------
<?php
header('Content-Type:text/html;charset=utf-8');
//@符号不要出现警告。
    //die函数之前,先连接一下 报错流程
    //if(!@mysql_connect('localhost:3306','root','passwor')){
    //echo '数据库连接失败,错误信息:'.mysql_error()';
    //exit;
    //}
 $conn=@mysql_connect('localhost:3306','root','passwor') or die('数据库连接失败,错误信息:'.mysql_error()')
echo $conn;
?>
------------------------------------------------------------------------
<?php  企业级的
define('DB_USER','root');
define('DB_PASSWORD','yangfan');
define('DB_HOST','localhost');
define('DB_NAME','school');
mysql_select_db();
//第一步连接数据库
$conn=@mysql_connect('DB_HOST','DB_USER','DB_PASSWORD') or die('数据库连接失败,错误信息:'.mysql_error()')
//选择指定的数据库
mysql_select_db(DB_NAME,$conn) or die('数据库错误'.mysql_error());    //返回为布尔值 
?>
--------------------------------------------------------------------------------
<?php  
@mysql_query('SET NAEMS UTF8') or die ('字符集设置错误');
define('DB_USER','root');
define('DB_PASSWORD','yangfan');
define('DB_HOST','localhost');
define('DB_NAME','school');
mysql_select_db();
//第一步连接数据库
$conn=@mysql_connect('DB_HOST','DB_USER','DB_PASSWORD') or die('数据库连接失败,错误信息:'.mysql_error()')
//2选择指定的数据库
mysql_select_db(DB_NAME,$conn) or die('数据库错误'.mysql_error());    //返回为布尔值 

//3从数据库里选一张表,并提出来(获取记录集)
$query="select * from grade";
$result=@mysql_query($query) or die('SQL错误,mysql错误');
//$result 就是数据集
print_r(msyql_fetch_array($result,MYSQL_ASSOC));
第五步释放记录集资源
mysql_free_result($result);
//最后一步,关闭数据库
echo mysql_close();
------------------------------
<?php
header('Content-Type:text/html;charset=utf-8');
define('DB_USER','root');
define('DB_PASSWORD','yangfan');
define('DB_HOST','localhost');
define('DB_NAME','school');
$conn=@mysql_connect('DB_HOST','DB_USER','DB_PASSWORD') or die('数据库连接失败,错误信息:'.mysql_error()')
mysql_select_db(DB_NAME,$conn) or die('数据库错误'.mysql_error());    //返回为布尔值 

@mysql_query('SET NAEMS UTF8') or die ('字符集设置错误');
-------------------demo2------------------
<?php
require 'conifg.php'
$query='INSERT INTO grade(
    name,
    email,
    point,
    regdate)
VALUES(
    '吴汽',
    'wq@sina.com.cn',
    88,

    NOW();
    )";
    mysql_query($query) or die ('新增错误:'.mysql_error());

    //$query='UPDATE grade SET point 87 WHERE id=8';
    
    //$query='DELETE FROM grade  WHERE id=8';
    //@mysql_querry($querry) or die ('删除错误'.mysql_error());
    
    显示数据
    $query="SELECT id,name,email,regdate,point FROM grade";
    $result=mysql_query($query) or die ('SQL语句有误:'.mysql_error());
    //print_r(mysql_fetch_array($result));
    //print_r(mysql_fetch_row($result));)
    //print_r(mysql_fetch_asssoc($result));
    
/*while(!!$row=mysql_fetch_array($result)){
echo $row['id'].'---'.$row['name'].'----'.$row['email'];
echo    mb_strlen($row['name'],'UTF-8');
echo '<br/>';
*/

}    
    
//echo  mysql_field_name($result,4);    
//echo  mysql_num_fields($result,4);    
//        
 for($i=0;$i<mysql_num_fields();$i++){
 
 echo mysql_field_name($result,$i);
 echo '---';

 }
echo '<br/>';
echo mysql_get_server_info();
echo mysql_get_host_info();
echo mysql_get_proto_info();
 echo mysql_num_row($result,$i);

    mysql_colse();

?>
--------------------------------basic.css-------------------------------------------
@CHARSET"UTF-8";
*{
 padding:0;
 margin:0;
 }
 body{
 width:960px;
 margin:0 auto;
 backgroud:#fff;
 font-size:14px;
 }
 ul{
 list-style-type:none;
 }
 h2{
 font-size:14px;
 backgroud:#eee;
 height:25px;
 line-height:25px;
 float:left;
 }
#header{
width:auto;
height:150px;
border:2px solid #ccc;
margin:10px 0;
}

#header h1{
font-size:12px;
width:210px;
height:39px;
backgroud:url(../../images/logo1.jpg) no-repeat;
margin:50px 0 0 50px
}
#header h1 a{
width:210px;
height:39px;
display:block;
text-indent:-9999px;
}
#header ul{

text-align:right;
padding:30px 50px 0 0
}
#header ul li{
display:inline;
}

#list{
width:600px;
height:514px;
border:2px solid #ccc;
float:right;
}
#user{
width:240px;
height:250px;
border:2px solid #ccc;
float:left;
}
#pics{
width:340px;
height:250px;
border:2px solid #ccc;
float:left;
}
#footer{
clear:both;
width:auto;
height:60px;
border:2px solid #ccc;
text-align:center;
padding:10px 0 0 0
}
#footer p{
font-size:12px;
letter-spacing:1px;
padding:5px 0 0 0;
}
#footer p span{ 
color:#06f;

--------------------------------多用户留言系统---------------------------
<link   rel="stylesheet" type="text/css" href="style/1/basic.css"/>
<div id="header">
<h1><a href="index.php">瓢虫web俱乐部多用户留言系统</a></h1>
<ul>
<li>首页</li>
<li>注册</li>
<li>登录</li>
<li>个人中心</li>
<li>风格</li>
<li>管理</li>
<li>退出</li>
</ul>
</div>
<div id="list">
<h2>帖子列表</h2>
</div>
<div id="user">
<h2>新进图片</h2>
</div>
<div id="pic">
<h2>最新图片</h2>
</div>
<div id="footer">
<p>版权所有 翻版必究</p>
<p>本程序由<span>瓢虫web俱乐部 </span>提供 (c) yc60.com</p>
</div>


------------------------index.css-------------------------------------

#list{
width:600px;
height:514px;
border:2px solid #ccc;
float:right;
}
#user{
width:240px;
height:250px;
border:2px solid #ccc;
float:left;
}
#pics{
width:340px;
height:250px;
border:2px solid #ccc;
float:left;
}
-----------------多用户留言系统 分离调用-----------------------------
new >>test0.2>>imoport>test1>>>>勾选所有的
-----------------------------------
将以上的注释信息添加到Templates模板指定的新建文件即可
<link rel="shortcuticon" href="favicon.ico"/>
调用ico文件
------------分离头尾------------------
建立一个文件夹include
建立./includes/header.inc.php 文件
-------调用-----------
<?php
require './includes/header.inc.php';
?>
------------------------
建立./includes/footer.inc.php 文件
<?php
require './includes/';
?>
-------防止恶意调用----------------------------
//防止恶意调用
if(!defined('IN_TG')){

exit('Access Denied!');
}
//定义常量
define('IN_TG,true');
---------------高效率-------------------------
建立文件common.inc.php
//引入公共文件

require dirname(_FILE_).'/includes/comman.inc/php'; //转换成硬路径会更快

--------------common.inc.php-----------
if(!defined('IN_TG')){

exit('Access Denied!');
}
define ('ROOT_PATH',substr(dirname(_FILE_),0,-8));
//引入
require ROOT_PATH.'include/global.func.php';
//define('START_TIME',=_runtime());
$GLOBALS['start_time']=_runtime();
--------调用-----
<?php
require ROOT_PATH.'includes/header.inc.php'

?>
------拒绝低版本-----------------
if(PHP_VERSION<'6.1.0'){
echo ('Version is to Low!');
}
-----------执行耗时------------
$_mtime=explode('',microtime());
print_r($_mtime);
$_start _time=$_mtime[1]+$_mtime[0];
---------------
结尾时间
$_mtime=explode('',microtime());
print_r($_mtime);
$_end_time=$_mtime[1]+$_mtime[0];
------------------
echo $_end_time-$_start_time;
--------睡眠函数
for($i=0;$i<1000000;$i++){
usleep(2000000);
}
---------------创建函数-----------
/**
*
*
*/
    function _runtime(){
    $_mtime=explode('',microtime());
    return $_mtime[1]+$_mtime[0];
    }
    /**_code()是验证码 函数
    *@param int @_width表示验证码的函数
    *access public
    */
function _code($_width = 75,$_height = 25;$_flag=flase;){
for($i=0;$i<4;$i++){
$_nmsg .= dechex(mt_rand(0,15)); 转换为十六进制 并累积
}
//echo $_nmsg
echo  $_SESSION['code']=$_nmsg;
    function _alert_back(){
    echo "<script type="text/javascript'>alert(‘非法操作!’);history.back();</script>"
    
    exit();
    
    
    }
---------------其他的页面------------------
//保存在session里
session_start();
echo  $_SESSION['code'];
//长和高

//创建一张图片
$_img = imagecreatetruecolor($_width,$_height);
//白色
$_white=imagecolorallocate($_img,255,255,255);
//填充
imagefill($_img,0,0,$_white);
//创建一个边框

if($_flag){
$_black = imagecolorallocate($_img,0,0,0);
imagerectangle($_img,0,0,$_width-1,$_heigth-1,$_rnd_color);
}


//随机画出线条
for($i=0;$i<6;$i++){
$_rnd_color=imagecolorallocate($_img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255))
imageline($_img,mt_rand(0,$_width),mt_rand(0,$_heigth),mt_rand(0,$_width),mt_rand(0,$_heigth),$_rnd_color);

}
//随机雪花
for($i=0;$i<100;$i++){
$_rnd_color=imagecolorallocate($_img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255))
imagestring($_img,1,mt_rand(1,$_width),mt_rand(1,$_height),mt_rand(1,_height),'$',$_rnd_color)
}
//输出验证码
for($i=0;$i<strlen($_SESSION['code']);$i++){
$_rnd_color=imagecolorallocate($_img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200))

imagestring($_img,5,$i*width/4+mt_rand(1,10),mt_rand(1,$_height/2),$_SESSON['code'][$i],$_rnd_color)

}

//输出图像
header('Content-Type:image/png');
imagepng($_img);
imagedestory($_img);
}
-------------------放到结尾------

 <p>本程序执行的耗时为:<?php echo round((_runtime()-START_TIME),4) ?>秒</p>

-------------------------注册界面----------------------------------
导入上一个版本
#header ul li a {
text-decoration:none;
color:#333;
}
#header ul  li a:hover{
color:#f00;
text-decoration:underline;
}
------------------------------------------------
<?php
session_start();
require ROOT_PATH.'includes/header.inc.php';
//定义个常量,用来授权
define('IN_TG',true);
用来指定本页的内容
define dirname(_FILE_).'/includes/commam.inc.php';
//判断是否提交了数据
if($_GET['action']=='registry'){

//防止恶意注册 跨站攻击
if ($_POST['yzm']==$_SESSION['code']
$_usernaem = $_POST['username'];
echo $_username;
}else{
_alert_back('验证码不正确');
}


?>
<div id="registry">
<h2>会员注册</h2>
<form method="post"  name="registry" action="registry.php?action=registry">
//<input type="hidden" name="action" value=registry>
<dl>
<dt>请认真填写以下内容</dt>
<dd>用户名:<input type="text"  name="username" class="text"/>(*必填,*)</dd>
<dd>密码:<input type="password"  name="password" class="text"/></dd>
<dd>确认密码:<input type="password"  name="notpassword" class="text"/></dd>
<dd>密码提示:<input type="text"  name="username" class="text"/></dd>
<dd>性别:<input type="radio"  name="sex" value="男" checked="checked"/>男<input type="radio"  name="sex" value="女" />女</dd>
<dd>< class="face" img src="face/m01.gif"  alt="头像选择 " οnclick="javascript:window.open('face.php','face','width=400'top=0,left=0,scrollbars=1' )"/></dd>
<dd>电子邮件:<input type="text"  name="email" class="text"/></dd>

<dd> QQ :<input type="text"  name="QQ" class="text"/></dd>
<dd>主页地址:<input type="text"  name="url" class="text" value="http://"/></dd>
<dd>验证码:<input type="text"  name="yzm" class="text yzm"/><src="code.php" id="code" οnclick="javascript:this.src='code.php?tm='+Math.random()""></dd>
<dd><input type="submit" class="submit" value="注册"></dd>
<=</dl>
</div>

<?php
require ROOT_PATH.'includes/footer.inc.php';
?>

-------------------registry.css------
@CHARSET "UTF-8";

#registry{
width:auto;
height:600px;
border:2px solid #ccc;
font-size:12px;
}
#registry h2{
text-indent:0;
text-align:center;
}
#registry dl{

aidth:400px;
margin:0 auto;

}
#regitry dl dt{
text-align:center;
padding:10px 0;
font-weight:bold;
}
#registry{
padding:5px 0;

}
#registry dl dd img#code{
posotion:relative;
top:8px;
cursor:pointer

}
#registry dl dd input.text{
width:220px;
height:19px;
border:1 px dashed #333
backgroud:#fff;
}
#registry dl dd.face{
padding:5px 0 5px 100px;

}
#registry dl dd input.submit{
width:60px;
height:19px;
border:1 px dashed #333;
background:#fff;
cursor:pointer;
margin: 0 0 0 120px;

}
#registry dl dd input.yzm{
width:60px;
}
#registry dl dd input img{
cursor:pointer;
}
-------------------------------------选择头像----------------------------------------
将css做成包含文件
创建inc.php
if(!defined('IN_TG')){

exit('Access Denied!');
}
//定义一个常量,用来指定本页的内容

define ('SCRIPT','index');  //只允许指定的页面调用 index

------------------face------------
<?php
require ROOT_PATH.'include/title.inc/php';
  <div id="face">
<h3>选择头像</h3>

<dl>
<?php for($i=0;$i<10;$i++){?>
<dd><img src="face/m01.gif" alt="头像1"></dd>
<?php}?>
-------------face.css
body{
width:auto;
}
#face  h3{
width:80%;
margin:10px auto;
height:30px;
line-height:30px;
text-align:center;
border:1px dashed  #333}
}
#face dl{
width:80%;
margin: 0 auto;

}
#face dl dd{
width:103px;
text-align:center;
float:left;

}
-----------foreach----------------
foreach(range(1,9) as $number ) {
echo $number.'|';

}
------------------------------
<?php foreach(range(1,9) as $num){?>
<dd><img src="face/m0<?php echo $num?>.gif" alt="头像"<?php
>


-----------验证码函数---------------mt_rand- 随机函数-----------------
session_start();
//创建随机码

//定义常量 授权调用include里面的文件
define('IN_TG',true);
//引入公共文件
require dirname(_FILE_).'/includes/common.inc.php'
//运行验证码 函数
_code(75,25,true);
//可以通过数据库的方式
--------------------------------------提交数据----------------------

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值