/**
* 根据指定的键值对数组排序
*
* @param array $array 要排序的数组
* @param string $keyname 键值名称
* @param int $sortDirection 排序方向
*
* @return array
*/
function arraySort($array, $keyname, $sortDirection = SORT_ASC)
{
return arrayMultiFields($array, array($keyname => $sortDirection));
}
php 文件读入与写入函数
<?php
//文件读取函式
function PHP_Read($file_name) {
$fd=fopen($file_name,r);
while($bufline=fgets($fd, 4096)){
$buf.=$bufline;
}
fclose($fd);
return $buf;
}
?>
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 mysql ip地址所在城市查询代码-ip数据库
<?
$servername ='localhost';
$dbname='test'; //数据库名
$dbusername ='root'; //数据库用户名
$dbpassword ='root'; //数据库密码
$link=mysql_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname) or die();
mysql_query("set names 'gbk'");
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);
?>
php 创建缩略图实例教程
本教程将介绍如何创建使用PHP的飞行缩略图。此外您将学习如何处理的图像整个文件夹,并创建自己的缩略图。因为这需要GD库,您将需要至少有一个广东2.0.1 PHP安装启用。
从数组中删除空白的元素(包括只有空白字符的元素)
/**
*
*
* @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;
}