首页 > phper

简单的目录删除程序

简单的目录删除程序
<?http://www.phprm.com
//目录删除函式
function del_DIR($directory){
$mydir=dir($directory);
while($file=$mydir->read()){
if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")){
del_DIR("$directory/$file");
}else{
if(($file!=".") AND ($file!="..")){
unlink("$directory/$file");
//echo "unlink $directory/$file ok
";
}
}
}
$mydir->close();
rmdir($directory);
//echo "rmdir $directory ok
";
}
?>

阅读全文

php ENCODE编码,DECODE解码

/**
 * @ string $str 要编码的字符串
 * @ string $ende 操作ENCODE编码,DECODE解码
 * @ string $key hash值
 * @return string
 */
function code($str, $ende, $key = '') {
 $coded = '';
 $keylength = strlen($key);
 $str = $ende == 'DECODE' ? base64_decode($str) : $str;
 for($i = 0; $i < strlen($str); $i += $keylength) {
  $coded .= substr($str, $i, $keylength) ^ $key;
 }
 $coded = $ende == 'ENCODE' ? str_replace('=', '', base64_encode($coded)) : $coded;
 return $coded;
}
我要们要 ENCODE编码,DECODE解码 只要设置$ende的参数就行了。

阅读全文

将一个二维数组转换为 hashmap 哈希表

/**
 * 将一个二维数组转换为 hashmap
 *
 * 如果省略 $val 参数,则转换结果每一项为包含该项所有数据的数组。
 *
 * @param array $arr
 * @param string $keyField
 * @param string $val
 *
 * @return array
 */
function arrHash(& $arr, $keyField, $val = null)
{
    $ret = array();
    if ($val) {
        foreach ($arr as $row) {
            $ret[$row[$keyField]] = $row[$val];
        }
    } else {
        foreach ($arr as $row) {
            $ret[$row[$keyField]] = $row;
        }
    }
    return $ret;
}

阅读全文

从数组中删除空白的元素(包括只有空白字符的元素)

 /**
 *
 *
 * @param array $arr
 * @param boolean $trim
 */
function delete_empty(& $arr, $trim = true)
{
    foreach ($arr as $key => $value) {
        if (is_array($value)) {
            delete_empty($arr[$key]);
        } else {
            $value = trim($value);
            if ($value == '') {
                unset($arr[$key]);
            } elseif ($trim) {
                $arr[$key] = $value;
            }
        }
    }
}

阅读全文

php 创建图片程序实例

<?php
$height = 300;
$width = 300;
 
$image = ImageCreate($width, $height);
 
$grey = ImageColorAllocate($image, 125, 125, 125);
$blue = ImageColorAllocate($image, 0, 0, 255);
$red = ImageColorAllocate($image, 255, 0, 0);
 
ImageString ($image, 4, 50, 50, "Size 4 Font", $red);
ImageString ($image, 5, 50, 100, "Size 5 Font", $blue);
 
ImageLine($image, 0, 0, 300, 300, $blue);
 
 
header ("Content-type: image/png");
ImagePng($image);
ImageDestroy($image);
?>

阅读全文