php图片上传功能,以二进制数据模式实现。
主要功能:
1,将文件存到项目路径下,保存图片的路径。
2,二进制的数据生成对应的图片,把二进制的数据,比如说图片文件和HTML文件,直接保存在MySQL数据库。
首先,实现PHP自动将图片转换成BASE64的代码。
如下:
function base64_encode_image ($filename='string',$filetype='string') {
if ($filename) {
$imgbinary = fread(fopen($filename, "r"), filesize($filename));
//file_put_contents('b.png',$imgbinary);
return 'data:image/' . $filetype . ';base64,' . base64_encode($imgbinary);
}
}
?>
<img src="/blog_article/</php echo base64_encode_image (.html'a.png','png'); ?>"/>
二、在MySQL中建立一个新的database
首先,在MySQL中建立一个新的数据库,将会把那些二进制文件储存在这个数据库里。
步骤:
`id` int(4) NOT NULL AUTO_INCREMENT,
`description` char(50) DEFAULT NULL,
`bin_data` longblob,
`filename` char(50) DEFAULT NULL,
`filesize` char(50) DEFAULT NULL,
`filetype` char(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;
输入命令:
if ($_FILES ['myfile'] != "none" && $_FILES ['myfile'] != "") {
$time_limit = 60;
set_time_limit ( $time_limit );
$file_type = $_FILES ['myfile'] ['type'];
$file_name = $_FILES ['myfile'] ['name'];
$file_size = $_FILES ['myfile'] ['size'];
$fp = fopen ( $_FILES ['myfile'] ['tmp_name'], "rb" );
if (! $fp)
die ( "file open error" );
$file_data = addslashes() ( fread ( $fp, $file_size ) );
fclose ( $fp );
/** 等价
$file_data = file_get_contents($_FILES["myfile"]['tmp_name']);
*/
$conn = mysql_connect() ( "localhost", "root", "root" );
if (! $conn)
die ( "error : mysql connect failed" );
mysql_select_db ( "test", $conn );
$sql = "insert into receive(file_data,file_type,file_name,file_size)values ('$file_data','$file_type','$file_name',$file_size)";
$result = mysql_query() ( $sql );
$id = mysql_insert_id ();
mysql_close ( $conn );
set_time_limit ( 30 ); //恢复缺省超时设置
echo "上传成功--- ";
echo "<a href='/blog_article/show_info/id/$id.html'>显示上传文件信息</a>";
} else {
echo "你没有上传任何文件";
}
?>
文件show_add.php //从数据库里取出文件内容
$data = mysql_result($result, 0, "file_data");
$type = mysql_result($result, 0, "file_type");
$fileName = mysql_result($result, 0, "file_name");
mysql_close($conn);
$filePath = 'download/' . $userid . "/" . $fileName;
file_put_contents($fileName,$data);
header('Location: /download.php?fileName=' . $fileName . '&file=' . $filePath);
/*
//download.php
$fileName = $_GET['fileName'];
$file_dir = RelativePath . $_GET['file'];
$file = @ fopen($file_dir, "r");
if (!$file) {
echo "File does not exist.";
} else {
ob_end_clean();
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=" . $fileName);
while (!feof($file)) {
echo fread($file, 50000);
}
fclose($file);
}
*/
?>
本节主要内容:
php中文支持函数:中文截取字符串、中文字符串翻转。
例1,
/**
* 将一个字串中含有全角的数字字符、字母、空格或'%+-()'字符转换为相应半角字符
*
* @access public
* @param string $str 待转换字串
*
* @return string $str 处理后字串
*/
function make_semiangle($str)
{
$arr = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4',
'5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9',
'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E',
'F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J',
'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O',
'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T',
'U' => 'U', 'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y',
'Z' => 'Z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd',
'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i',
'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n',
'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's',
't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x',
'y' => 'y', 'z' => 'z',
'(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[',
'】' => ']', '〖' => '[', '〗' => ']', '“' => '[', '”' => ']',
'‘' => '[', '’' => ']', '{' => '{', '}' => '}', '《' => '<',
'》' => '>',
'%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-',
':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.',
';' => ',', '?' => '?', '!' => '!', '…' => '-', '‖' => '|',
'”' => '"', '’' => '`', '‘' => '`', '|' => '|', '〃' => '"',
' ' => ' ','$'=>'$','@'=>'@','#'=>'#','^'=>'^','&'=>'&','*'=>'*');
return strtr($str, $arr);
}
例2,php中文截取字符串
/*
Utf-8、gb2312都支持的汉字截取函数
cut_str(字符串, 截取长度, 开始长度, 编码);
编码默认为 utf-8
开始长度默认为 0
* edit: www.
*/
function cut_str($string, $sublen, $start = 0, $code = 'UTF-8') {
if ($code == 'UTF-8') {
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all ( $pa, $string, $t_string );
if (count ( $t_string [0] ) - $start > $sublen)
return join ( '', array_slice ( $t_string [0], $start, $sublen ) ) . "...";
return join ( '', array_slice ( $t_string [0], $start, $sublen ) );
} else {
$start = $start * 2;
$sublen = $sublen * 2;
$strlen = strlen ( $string );
$tmpstr = '';
for($i = 0; $i < $strlen; $i ++) {
if ($i >= $start && $i < ($start + $sublen)) {
if (ord ( substr ( $string, $i, 1 ) ) > 129) {
$tmpstr .= substr ( $string, $i, 2 );
} else {
$tmpstr .= substr ( $string, $i, 1 );
}
}
if (ord ( substr ( $string, $i, 1 ) ) > 129)
$i ++;
}
if (strlen ( $tmpstr ) < $strlen)
$tmpstr .= "...";
return $tmpstr;
}
}
$str = "abcd需要截取的字符串";
echo cut_str ( $str, 1, 0, 'gb2312' );
?>
例3,字符串的载取
/**
* 字符截取 支持UTF8/GBK
* @param $string
* @param $length
* @param $dot
*/
function str_cut($string, $length, $charset = 'utf-8', $dot = '...') {
$strlen = strlen($string);
if($strlen <= $length) return $string;
$string = str_replace()(array(' ',' ', '&', '"', ''', '“', '”', '—', '<', '>', '·', '…'), array('∵',' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), $string);
$strcut = '';
if(strtolower()($charset) == 'utf-8') {
$length = intval($length-strlen($dot)-$length/3);
$n = $tn = $noc = 0;
while($n < strlen($string)) {
$t = ord($string[$n]);
if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
$tn = 1; $n++; $noc++;
} elseif(194 <= $t && $t <= 223) {
$tn = 2; $n += 2; $noc += 2;
} elseif(224 <= $t && $t <= 239) {
$tn = 3; $n += 3; $noc += 2;
} elseif(240 <= $t && $t <= 247) {
$tn = 4; $n += 4; $noc += 2;
} elseif(248 <= $t && $t <= 251) {
$tn = 5; $n += 5; $noc += 2;
} elseif($t == 252 || $t == 253) {
$tn = 6; $n += 6; $noc += 2;
} else {
$n++;
}
if($noc >= $length) {
break;
}
}
if($noc > $length) {
$n -= $tn;
}
$strcut = substr($string, 0, $n);
$strcut = str_replace(array('∵', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), array(' ', '&', '"', ''', '“', '”', '—', '<', '>', '·', '…'), $strcut);
} else {
$dotlen = strlen($dot);
$maxi = $length - $dotlen - 1;
$current_str = '';
$search_arr = array('&',' ', '"', "'", '“', '”', '—', '<', '>', '·', '…','∵');
$replace_arr = array('&',' ', '"', ''', '“', '”', '—', '<', '>', '·', '…',' ');
$search_flip = array_flip($search_arr);
for ($i = 0; $i < $maxi; $i++) {
$current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
if (in_array($current_str, $search_arr)) {
$key = $search_flip[$current_str];
$current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str);
}
$strcut .= $current_str;
}
}
return $strcut.$dot;
}
例4,PHP中文字符串翻转
翻转一个字符串可以使用strrev()函数即可。
但有时需要处理是字符串是含中文的,这样用strrev就会出现乱码。
这里自定义一个函数来处理含中文的字符。
<?php
/**
* 中文字符串翻转
* by www.
*/
function cstrrev($str)
{
$len = strlen($str);
for($i = 0; $i < $len; $i++)
{
$char = $str{0};
if(ord($char) > 127)
{
$i++;
if($i < $len)
{
$arr[] = substr($str, 0, 2);
$str = substr($str, 2);
}
}
else
{
$arr[] = $char;
$str = substr($str, 1);
}
}
return join(array_reverse($arr));
}
#使用方法:
$str = '中文.look!';
echo cstrrev($str);
#结果输出:!kool.文中
附5,
function str_replace_cn($needle, $str, $haystack, $charset = "utf-8"){
$re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
$re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
$re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
preg_match_all($re[$charset], $haystack, $match_haystack);
preg_match_all($re[$charset], $needle, $match_needle);
for($i = 0; $i < count($match_needle); $i ++){
if(!in_array($match_needle[0][$i], $match_haystack[0]))return $haystack;//无匹配
}
$match_haystack = $match_haystack[0];
$match_needle = $match_needle[0];
for($i = 0; $i < count($match_haystack); $i ++){
if($match_haystack[$i] == "")continue;
if($match_haystack[$i] == $match_needle[0]){
if(count($match_needle) == 1){//如果只一个字符
$match_haystack[$i] = $str;
}else{
$flag = true;
for($j = 1; $j < count($match_needle); $j ++){
if($match_haystack[$i + $j] != $match_needle[$j]){
$flag = false;
break;
}
}
if($flag){//匹配
$match_haystack[$i] = $str;
for($j = 1; $j < count($match_needle); $j ++){
$match_haystack[$i + $j] = "";
}
}
}
}
}
return implode("", $match_haystack);
}
代码:
<?php
/*
* 数组转换成对象
$array = array('name' => 'one',
'sex' => 'two',
'test' => array('a' => 'ss', 'dd'),
'old' => 'three'
);
$arrayobject = array2Object($array);
echo $arrayobject->name; // one
print_r(object2Array($arrayobject));
*/
function array2Object($array) {
if (!is_array($array)) return $array;
$object = new stdClass();
if (is_array($array) && count($array) > 0) {
foreach ($array as $name => $value) {
$name = strtolower()(trim($name));
if ($name) $object->$name = array2Object($value);
}
return $object;
} else return FALSE;
}
/*
* 对象转换成数组
*/
function object2Array($objParam) {
$obj_param = ( array )$objParam;
foreach ($obj_param as $key => $value) {
if (is_object($value)) {
object2Array($value);
$obj_param [$key] = ( array )$value;
}
}
return $obj_param;
}
//数组《=》字符串
/**
* 将字符串转换为数组
*
* @param string $data 字符串
* @return array 返回数组格式,如果,data为空,则返回空数组
*/
function string2array($data) {
if ($data == '') return array();
eval("\$array = $data;");
return $array;
}
/**
* 返回经stripslashes()处理过的字符串或数组
* @param $string 需要处理的字符串或数组
* @return mixed
*/
function new_stripslashes($string) {
if (!is_array($string)) return stripslashes($string);
foreach ($string as $key => $val) $string[$key] = new_stripslashes($val);
return $string;
}
/**
* 将数组转换为字符串
* 数组入库比序列化函数直观
* @param array $data 数组
* @param bool $isformdata 如果为0,则不使用new_stripslashes处理,可选参数,默认为1
* @return string 返回字符串,如果,data为空,则返回空
*/
function array2string($data, $isformdata = 1) {
if ($data == '') return '';
if ($isformdata) $data = new_stripslashes($data);
return addslashes()(var_export($data, TRUE));
}
//数组《=》树
/**
* 将一个平面的二维数组按照指定的字段转换为树状结构
*
* 当 $returnReferences 参数为 true 时,返回结果的 tree 字段为树,refs 字段则为节点引用。
* 利用返回的节点引用,可以很方便的获取包含以任意节点为根的子树。
*
* @param array $arr 原始数据
* @param string $fid 节点ID字段名
* @param string $fparent 节点父ID字段名
* @param string $fchildrens 保存子节点的字段名
* @param boolean $returnReferences 是否在返回结果中包含节点引用
*
* return array
*/
function array_to_tree($arr, $fid, $fparent = 'parent_id',
$fchildrens = 'childrens', $returnReferences = false) {
$pkvRefs = array();
foreach ($arr as $offset => $row) {
$pkvRefs[$row[$fid]] =& $arr[$offset];
}
$tree = array();
foreach ($arr as $offset => $row) {
$parentId = $row[$fparent];
if ($parentId) {
if (!isset()($pkvRefs[$parentId])) {
continue;
}
$parent =& $pkvRefs[$parentId];
$parent[$fchildrens][] =& $arr[$offset];
} else {
$tree[] =& $arr[$offset];
}
}
if ($returnReferences) {
return array('tree' => $tree, 'refs' => $pkvRefs);
} else {
return $tree;
}
}
/**
* 将树转换为平面的数组
*
* @param array $node
* @param string $fchildrens
*
* @return array
*/
function tree_to_array(& $node, $fchildrens = 'childrens') {
$ret = array();
if (isset($node[$fchildrens]) && is_array($node[$fchildrens])) {
foreach ($node[$fchildrens] as $child) {
$ret = array_merge($ret, tree_to_array($child, $fchildrens));
}
unset($node[$fchildrens]);
$ret[] = $node;
} else {
$ret[] = $node;
}
return $ret;
}
附,PHP二维数组去重复项函数
function unique_array_2d($array2D,$stkeep=false,$ndformat=true)
{
// 判断是否保留一级数组键 (一级数组键可以为非数字)
if($stkeep) $stArr = array_keys()($array2D);
// 判断是否保留二级数组键 (所有二级数组键必须相同)
if($ndformat) $ndArr = array_keys(end($array2D));
//降维,也可以用implode,将一维数组转换为用逗号连接的字符串
foreach ($array2D as $v){
$v = join(",",$v);
$temp[] = $v; //www.
}
//去掉重复的字符串,也就是重复的一维数组
$temp = array_unique($temp);
//再将拆开的数组重新组装
foreach ($temp as $k => $v)
{
if($stkeep) $k = $stArr[$k];
if($ndformat)
{
$tempArr = explode()(",",$v);
foreach($tempArr as $ndkey => $ndval) $output[$k][$ndArr[$ndkey]] = $ndval;
}
else $output[$k] = explode(",",$v);
}
return $output;
}
$array2D = array(
'first'=>array('title'=>'1111','date'=>'2222'),
'second'=>array('title'=>'1111','date'=>'2222'),
'third'=>array('title'=>'2222','date'=>'3333')
);
echo "<pre>";
print_r(unique_array_2d($array2D,true));
/**
* 将二维数组通过指定的 key 去重
*
* @param array $arr 要去重的数组
* @param array $by 指定key去重,该参数不指定将返回 array()
* @return array
*/
function array_multunique($arr,$by = array()) {
$temp = array();
foreach($arr as $key => $val) {
foreach($by as $v) {
$temp[$key] .= isset($val[$v]) ? $val[$v] : '';
}
}
return array_intersect_key($arr,array_unique($temp));
}
/*$aa = array (
array ('id' => 123, 'name' => '张三' ),
array ('id' => 123, 'name' => '李四' ),
array ('id' => 124, 'name' => '王五' ),
array ('id' => 125, 'name' => '赵六' ),
array ('id' => 126, 'name' => '赵六' )
);
$key = 'id';
array_multunique ($aa, array('id')); */
function array_remove_key($array,$keys){
if (!is_array($array) || !is_array($keys)){
return false;
}
foreach($array as $t){
foreach($keys as $k){
unset($t[$k]);
}
$doc[]=$t;
}
return $doc;
}
/*$array = array(
'0' => array('a' => 'aaaaa', 'b' => 'bbbbb', 'c' => array('d' => 'ddddd', 'e' => 'eeeee')),
'1' => array('a' => 'aaaaa', 'b' => 'bbbbb', 'c' => array('d' => 'ddddd', 'e' => 'eeeee'))
);
print_r( array_remove_key($array,array('c')));*/
function array_remove_key_val(&$a,$b,$c){
foreach ($a as $key=>$value){
if ( isset($value[$b]) && ($value[$b]==$c) ){
unset($a[$key]);
}
}
}
/*$a=array(
array('id'=>1,'num'=>10,'type'=>'news'),
array('id'=>2,'num'=>100,'type'=>'pic')
);
print_r( array_remove_key_val($a,"id","1") );*/
附2,数组<=>xml 相互转换
/**
* 对数据进行编码转换
* @param array/string $data 数组
* @param string $input 需要转换的编码
* @param string $output 转换后的编码
*/
function array_iconv($data, $input = 'gbk', $output = 'utf-8') {
if (!is_array($data)) {
return iconv($input, $output, $data);
} else {
foreach ($data as $key => $val) {
if (is_array($val)) {
$data[$key] = array_iconv($val, $input, $output);
} else {
$data[$key] = iconv($input, $output, $val);
}
}
return $data;
}
}
//在数组的第三个位置后添加1个元素,如何做$a = array("a" => 1, "b" => 2, "c" => 4, "d" => 6);$a = array_insert($a, "add", 3);
function array_insert($myarray, $value, $position) {
$fore = array_splice($myarray, 0, $position);
$fore[] = $value;
$ret = array_merge($fore, $myarray);
return $ret;
}
/**
* 从数组中删除空白的元素(包括只有空白字符的元素)
*
* @param array $arr
* @param boolean $trim
*/
function array_remove_empty(& $arr, $trim = true) {
foreach ($arr as $key => $value) {
if (is_array($value)) {
array_remove_empty($arr[$key]);
} else {
$value = trim($value);
if ($value == '') {
unset($arr[$key]);
} elseif ($trim) {
$arr[$key] = $value;
}
}
}
}
/**
* 从一个二维数组中返回指定键的所有值
*
* @param array $arr
* @param string $col
*
* @return array
*/
function array_col_values(& $arr, $col) {
$ret = array();
foreach ($arr as $row) {
if (isset($row[$col])) {
$ret[] = $row[$col];
}
}
return $ret;
}
/**
* 将一个二维数组转换为 hashmap
*
* 如果省略 $valueField 参数,则转换结果每一项为包含该项所有数据的数组。
*
* @param array $arr
* @param string $keyField
* @param string $valueField
*
* @return array
*/
function array_to_hashmap(& $arr, $keyField, $valueField = null) {
$ret = array();
if ($valueField) {
foreach ($arr as $row) {
$ret[$row[$keyField]] = $row[$valueField];
}
} else {
foreach ($arr as $row) {
$ret[$row[$keyField]] = $row;
}
}
return $ret;
}
/**
* 将一个二维数组按照指定字段的值分组
*
* @param array $arr
* @param string $keyField
*
* @return array
*/
function array_group_by(& $arr, $keyField) {
$ret = array();
foreach ($arr as $row) {
$key = $row[$keyField];
$ret[$key][] = $row;
}
return $ret;
}
/**
* 根据指定的键值对数组排序
*
* @param array $array 要排序的数组
* @param string $keyname 键值名称
* @param int $sortDirection 排序方向
*
* @return array
*/
function array_column_sort($array, $keyname, $sortDirection = SORT_ASC) {
return array_sortby_multifields($array, array($keyname => $sortDirection));
}
/**
* 将一个二维数组按照指定列进行排序,类似 SQL 语句中的 ORDER BY
*
* @param array $rowset
* @param array $args
*/
function array_sortby_multifields($rowset, $args) {
$sortArray = array();
$sortRule = '';
foreach ($args as $sortField => $sortDir) {
foreach ($rowset as $offset => $row) {
$sortArray[$sortField][$offset] = $row[$sortField];
}
$sortRule .= '$sortArray[\'' . $sortField . '\'], ' . $sortDir . ', ';
}
if (empty($sortArray) || empty($sortRule)) {
return $rowset;
}
eval('array_multisort()(' . $sortRule . '$rowset);');
return $rowset;
}
/*
description: 交换数组中两个元素的位置,元素包括key和value,具体用法见下面的例子
$arr = array (11 => 'a', 22 => 'b', 33 => 'c', 44 => 'd' );
$res = array_exchange ( $arr, 11, 33 );
*/
function array_exchange($arr, $arg1, $arg2) {
$r = range(0, count($arr) - 1);
$res = $res_bak = array_combine($r, array_keys($arr));
$change = array($arg1, $arg2);
list ($res [array_search($change [0], $res_bak)], $res [array_search($change [1], $res_bak)]) = array($change [1], $change [0]);
foreach ($res as $v) {
$array [$v] = $arr [$v];
}
return $array;
}
/*
假设:给定一个大数组和一个字符串,要求在这个大数组中查找出比这个字符串大的5个元素。
对于一个小数组(如:几十个元素以下的数组),可以采用循环的办法来一个一个进行比较,但是对于大数组来说,这个方法显然是不行,这需要找一个快速查找定位的解决办法。
$search = 'arr';
$array = array (
'abs',
'addslashes',
'aggregate_info',
'array_diff',
'array_fill_keys',
'array_fill',
'array_filter',
'base64_encode',
'bccomp',
);
$arrpos = array_pos($array,$search); //定位
$arr = array_slice($array,$arrpos,5); //取出数组
print_r($arr);
快速查找的结果:
Array
(
[0] => array_diff
[1] => array_fill_keys
[2] => array_fill
[3] => array_filter
[4] => base64_encode
)
*/
function array_pos($array, $search) {
if (empty($array)) return false;
if (!$search) return 0;
sort($array);
$array_turn = array_flip($array);
if (isset($array_turn[$search])) {
$arrpos = $array_turn[$search];
} else {
$tmp_arr = $array;
$tmp_arr[] = $search;
sort($tmp_arr);
$tmp_arr_turn = array_flip($tmp_arr);
$arrpos = $tmp_arr_turn[$search];
}
return $arrpos;
}
//数组开头添加元素 保持原始key不变 arrayUnshift($arr, array('test'=>'4'))
function arrayUnshift($arrParams, $arrAdd) {
$arr_keys = array();
$arr_values = array();
$arr_add_keys = array_keys($arrAdd);
$arr_keys = array($arr_add_keys [0]);
$arr_values = array($arrAdd [$arr_add_keys [0]]);
foreach ($arrParams as $key => $value) {
array_push($arr_keys, $key);
array_push($arr_values, $value);
}
$arr_result = array_combine($arr_keys, $arr_values);
return $arr_result;
}
//获取多维数组下特定键下的值,并生成一维数组
function getKey2Array(array $arr, $key) {
if (!trim($key)) return false;
preg_match_all("/\"$key\";\w{1}:(?:\d+:|)(.*?);/", serialize($arr), $output);
return $output[1];
}
//多维数组转一维数组 $arr=array('123.html','456.html',array('dw.html','fl.html',array('ps.html','fw.html')),'ab.html');
function rebuild_array($arr) { //rebuild a array
static $tmp = array();
for ($i = 0; $i < count($arr); $i++) {
if (is_array($arr[$i])) {
rebuild_array($arr[$i]);
} else {
$tmp[] = $arr[$i];
}
}
return $tmp;
}