51cto-php基础知识-孙胜利

一、学前准备

 

二、PHP基本语法


三、流程控制


四、函数


五、数组


六、字符串处理


七、正则表达式


八、日期与时间

一、设置时区
    date_default_timezone_set('Asia/Shanghai');//设置时区
二、获取当前Unix时间戳
    time()
三、获取指定时间的Unix时间戳
    mktime()
    date_default_timezone_set('Asia/Shanghai');//设置时区
    $nowTime=time();
    $time1=mktime(0,0,0,10,1,2014);//取得一个日期的 Unix 时间戳
    echo '距离2014年国庆还有'.(($time1-$nowTime)/60/60/24).'天';
四、从Unix时间戳取得时间日期信息
    date()格式化一个本地时间/日期
    第一个参数:必填,写上你所需要的时间日期的格式,把format 字符放在第一个参数里面会被转换成对应的信息,其他的字符还是原来的样子
    date('Y-m-d G:i:s')
    自定义格式化Unix时间戳 为指定的时间格式!
五、获取Unix时间戳和微秒数
    microtime() 返回当前 Unix 时间戳和微秒数
    var_dump(microtime());
    var_dump(microtime(true));
    
web的日期与时间设置

 

九、图像处理

 

学前了解:
    在PHP中可以通过GD库处理图像
创建一个图像应该完成如下所示的四个基本步骤:
    1.创建图像
    2.绘制图像
    3.输出图像
        header函数注意点
        在该函数之前,不能输出任何内容
        
        在我们的PHP代码 的函数里面,我们使用的/开头的路径 这个/不是指 web根目录,而是操作系统的 文件的根目录!
        
    4.释放资源


设计验证码的步骤:
创建图像的步骤

 

后台登陆验证码

<?php
header('Content-type:image/jpeg');
$width=120;
$height=40;
$element=array('a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$string='';
for ($i=0;$i<5;$i++){
    $string.=$element[rand(0,count($element)-1)];
}
$img=imagecreatetruecolor($width, $height);
$colorBg=imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));
$colorBorder=imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));
$colorString=imagecolorallocate($img,rand(10,100),rand(10,100),rand(10,100));
imagefill($img,0,0,$colorBg);
imagerectangle($img,0,0,$width-1,$height-1,$colorBorder);
for($i=0;$i<100;$i++){
    imagesetpixel($img,rand(0,$width-1),rand(0,$height-1),imagecolorallocate($img,rand(100,200),rand(100,200),rand(100,200)));
}
for($i=0;$i<3;$i++){
    imageline($img,rand(0,$width/2),rand(0,$height),rand($width/2,$width),rand(0,$height),imagecolorallocate($img,rand(100,200),rand(100,200),rand(100,200)));
}
//imagestring($img,5,0,0,'abcd',$colorString);
imagettftext($img,14,rand(-5,5),rand(5,15),rand(30,35),$colorString,'font/SketchyComic.ttf',$string);
imagejpeg($img);
imagedestroy($img);
后台登陆验证码

水印

 

缩放与裁剪

 


十、文件与目录


十一、回话控制

 

 

 

 

 

posted @ 2020-07-02 23:42  千机楼  阅读(210)  评论(0)    收藏  举报