您的位置:首页 > 编程语言 > PHP开发

一些PHP函数

2011-05-31 14:39 253 查看
<?php
/* 将URL中的某参数设为某值*/
function url_set_value($url,$key,$value)
{
$a=explode('?',$url);
$url_f=$a[0];
$query=$a[1];
parse_str($query,$arr);
$arr[$key]=$value;
return $url_f.'?'.http_build_query($arr);
}

//copy a direction’s all files to another direction
function xCopy($source, $destination, $child = false){
//用法:
// xCopy("feiy","feiy2",1):拷贝feiy下的文件到 feiy2,包括子目录
// xCopy("feiy","feiy2",0):拷贝feiy下的文件到 feiy2,不包括子目录
//参数说明:
// $source:源目录名
// $destination:目的目录名
// $child:复制时,是不是包含的子目录
if(!is_dir($source)){
echo("Error:the $source is not a direction!");
return 0;
}
if(!is_dir($destination)){
mkdir($destination,0777);
}
$handle=dir($source);
while($entry=$handle->read()) {
if(($entry!=".")&&($entry!="..")){
if(is_dir($source."/".$entry)){
if($child)
xCopy($source."/".$entry,$destination."/".$entry,$child);
}
else{
copy($source."/".$entry,$destination."/".$entry);
}
}
}
return 1;
}

///获取与当前PHP同一层的另外一个文件的全链接
$self_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
$last_slash_pos = strrpos($self_url, '/');
$cur_dir_url = substr($self_url, 0, $last_slash_pos);
$otherjumpurl = $cur_dir_url + "XXXX.php";

//设置网页编码为utf8
@header('Content-Type:text/html;charset=utf-8')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: