首页 > PHP教程

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的参数就行了。

阅读全文

简单的目录删除程序

简单的目录删除程序
<?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 获取QQwry.dat真实IP地址

<?http://www.phprm.com
//===================================
//
// 功能:IP地址获取真实地址函数
// 参数:$ip - IP地址
//
//===================================
function convertip($ip) {
$dat_path = '../QQWry.Dat';       
if(!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/", $ip)) {
return 'IP Address Error';

if(!$fd = @fopen($dat_path, 'rb')){
return 'IP date file not exists or access denied';

$ip = explode('.', $ip);
$ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3]; 
$DataBegin = fread($fd, 4);
$DataEnd = fread($fd, 4);
$ipbegin = implode('', unpack('L', $DataBegin));
if($ipbegin < 0) $ipbegin += pow(2, 32);
$ipend = implode('', unpack('L', $DataEnd));
if($ipend < 0) $ipend += pow(2, 32);
$ipAllNum = ($ipend - $ipbegin) / 7 + 1;
$BeginNum = 0;
$EndNum = $ipAllNum; 
while($ip1num>$ipNum || $ip2num<$ipNum) {
$Middle= intval(($EndNum + $BeginNum) / 2);
fseek($fd, $ipbegin + 7 * $Middle);
$ipData1 = fread($fd, 4);
if(strlen($ipData1) < 4) {
fclose($fd);
return 'System Error';
}
$ip1num = implode('', unpack('L', $ipData1));
if($ip1num < 0) $ip1num += pow(2, 32);

阅读全文

php 文件下载安全

此脚本防止文件被链接到其他文件,因为这迫使脚本文件被下载之前在下载开始。这个脚本是非常重要的高度机密的文件。

在此脚本,filter_var()用于过滤文件和有效的字符串验证的文件,该文件使用过滤器将下载的文件FILTER_SANITIZE_STRING。

阅读全文

php 在服务器上载文件

这个例子将解释您如何上传FTP服务器上的文件。 ftp_put()命令允许上传在服务器上现有的文件。对于上传到FTP服务器的文件,首先你必须先登录到FTP服务器上,搜索源文件上传。定义源文件的目标路径。

阅读全文

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);
?>

阅读全文

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

 /**
 *
 *
 * @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;
            }
        }
    }
}

阅读全文

将一个二维数组转换为 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;
}

阅读全文