
php取随机数
<?php
function randomkeys($length)
{
$pattern='1234567890';
for($i=0;$i<$length;$i++)
{
$key .= $pattern{mt_rand(0,10)}; //生成php随机数
}
return $key;
}
echo randomkeys(9);
?>
explode劫取字符串
$source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离字符串
$hello = explode(',',$source);
for($index=0;$index<count($hello);$index++)
{
$hello1=$hello[$index];
echo $hello[$index];echo "</br>";
echo $hello1;
echo "</br>";
}
时间定义随机数
<?php
date('YmdHis').rand(1000,9999)
?>
更改文件名
date()//得到当前时间,格式自己定!
如;假设当前上传的文件叫'1.jpg',你的文件域名叫file,上传的文件在根目录下面;
$date=date('Ymdhis');//得到当前时间,如;20070705163148
$fileName=$_FIFLES['file']['name'];//得到上传文件的名字
$name=explode('.',$fileName);//将文件名以'.'分割得到后缀名,得到一个数组
$newPath=$date.'.'.$name[1];//得到一个新的文件为'20070705163148.jpg',即新的路径
$oldPath=$_FILES['file']['tmp_name'];//临时文件夹,即以前的路径
rename($oldPath,$newPath);就可以重命名了!