代码如下 | 复制代码 |
<?php教程 |
index.php验证码生成程序
代码如下 | 复制代码 |
<?php
imagestring($im,5,15,8,$rand,$wh);//字体,1-6 header("Content-type: image/jpeg");//输出图片
|
效果图。
index.php教程
代码如下 | 复制代码 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <body> <div id="box"> |
数据库教程连接 connect.php
代码如下 | 复制代码 |
<?php |
图片验证码 piccheck.php
代码如下 | 复制代码 |
<?php /* * Created on 2011-8-10 * * To change the template for this generated file go to * Window - Preferences - PHPeclips教程e - PHP - Code Templates */ session_start(); $code=rand(0,9).dechex(rand(10,15)).rand(0,9).dechex(rand(10,15)); $_SESSION[pic]=$code; $image=imagecreatetruecolor(50,18); $color=imagecolorallocate($image,0,0,0);//第一次使用调色板,会设为背景颜色 $colortext=imagecolorallocate($image,rand(100,255),rand(100,255),rand(100,255)); imagestring($image,10,rand(1,15),rand(1,5),$code,$colortext); imagegif($image); ?> |
css.css文件
代码如下 | 复制代码 |
@charset "utf-8"; body { |
下面是一个将datetime日期时间转换成年', '个月', '天', '小时', '分种', '秒'来显示,有需要的朋友可以参考一下。
/**
* 友好日期时间
*
* @param DateTime $datetime 日期时间
* @param int $size 精确到位数
* @throws InvalidArgumentException
* @return string
*/
function friendly_date($datetime, $size=1)
{
if (is_int($datetime)) {
$datetime = new DateTime($datetime);
}
if (!($datetime instanceof DateTime)) {
throw new InvalidArgumentException('invalid "DateTime" object');
}
$now = new DateTime();
$interval = $now->diff($datetime);
$intervalData = array(
$interval->y, $interval->m, $interval->d,
$interval->h, $interval->i, $interval->s,
);
$intervalFormat = array('年', '个月', '天', '小时', '分种', '秒');
foreach($intervalData as $index=>$value) {
if ($value) {
$intervalData[$index] = $value . $intervalFormat[$index];
} else {
unset($intervalData[$index]);
unset($intervalFormat[$index]);
}
}
return implode('', array_slice($intervalData, 0, $size));
}
你自己也一个 函数呀 php教程 内置的很多函数都有问题(不是错误,是适用方位窄)
for(旧数组.....){
if(是要删除的值)
continue
$newArr[]=每个值
}
return $newArr
实例
Array([0] => Hello[1] => world.[2] => It's[3] => a[4] => beautiful[5] => day.)
foreach($array as $k=>$v){
if($v == 'day'){
unset($array[$k]):
}
}
利用foreach效率不高下在, 看php自带函数
$arr = array("Hello","world","It's","beautiful","day");
实例一
$arr = array_flip($arr);
unset($arr['world']);
$arr = array_flip($arr);
print_r($arr);
实例二
array_search() 函数与 in_array() 一样,在数组中查找一个键值。如果找到了该值,匹配元素的键名会被返回。如果没找到,则返回 false。
$arr = Array([0] => Hello[1] => world.[2] => It's[3] => a[4] => beautiful[5] => day.);
if(($key = array_search('day',$arr))){
unset($arr[$key]);
}
实例三
array_splice() 函数与 array_slice() 函数类似,选择数组中的一系列元素,但不返回,而是删除它们并用其它值代替。
if(($key = array_search('day',$arr))){
array_splice($arr, $key,1);
}
php教程获取上传文件名的文件类型
$imgname = $_FILES["file"]["name"]; //获取上传的文件名称
$filetype = pathinfo($imgname, PATHINFO_EXTENSION);//获取后缀
$newname = date("Ymdhis").".".$filetype; //构建新名称
再看
$file = 'www.111cn.net.gif';
echo getfix( $file );
//得到的值为gif 这种方法最简单也最实例了,好下面我们来看看方法二一种用substr读取扩展名方法
$file ='aaa.gif';
echo substr($file,strpos($file,'.')+1);
//方法三 还是用数组
$file = '111cn.gif';
$d111cn = explode('.',$file);
echo $d111cn[count($d111cn)-1];function getfix($l1){
return end(explode('.', $l1));
}
$extname=substr($upload_file_name,strpos($upload_file_name,".")+1);//获取文件扩展名
strpos() 函数返回字符串在另一个字符串中第一次出现的位置。如果没有找到该字符串,则返回 false。
更多详细内容请查看:http://www.111cn.net/phper/21/358ad3dd52a90fd7894a1047adc80208.htm