00001 <?php
00002 ############################################################################
00003 # Copyright (C) 2004 by Paolo Armani & Stefano Menegon #
00004 # paolo.armani@gmail.com menegon@itc.it #
00005 # #
00006 # This program is free software; you can redistribute it and#or modify #
00007 # it under the terms of the GNU Library General Public License as #
00008 # published by the Free Software Foundation; either version 2 of the #
00009 # License, or (at your option) any later version. #
00010 # #
00011 # This program is distributed in the hope that it will be useful, #
00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
00014 # GNU General Public License for more details. #
00015 # #
00016 # You should have received a copy of the GNU Library General Public #
00017 # License along with this program; if not, write to the #
00018 # Free Software Foundation, Inc., #
00019 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
00020 ############################################################################
00021
00023
00029 function array_to_hash($arr1,$arr2){
00030 $resArr=array();
00031 if(is_array($arr2) && is_array($arr1)){
00032 $num=min(count($arr1),count($arr2));
00033 reset($arr1);
00034 reset($arr2);
00035 for($i=0; $i<$num; $i++){
00036 $resArr[current($arr1)]=current($arr2);
00037 next($arr1);
00038 next($arr2);
00039 }
00040 }
00041 return $resArr;
00042 }
00043
00045
00050 function transpose($arr){
00051 $arr1=array();
00052 if(is_array($arr)){
00053 foreach($arr as $key=>$val){
00054 if(is_array($val)){
00055 foreach($val as $key1=>$val1){
00056 $arr1[$key1][$key]=$val1;
00057 };
00058 };
00059 }
00060 };
00061 return $arr1;
00062 }
00063
00065
00067
00068
00070
00075 function isodate($datearr){
00076 if(is_array($datearr) && $datearr['month']>0 && $datearr['day'] >0 && $datearr['year'] >0 ){
00077 $isodate=$datearr['year'].'-'.$datearr['month'].'-'.$datearr['day'];
00078 }else{
00079 $isodate='';
00080 }
00081 return $isodate;
00082 }
00083
00085
00090 function is_date($datearr){
00091 return checkdate($datearr['month'],$datearr['day'],$datearr['year']);
00092 }
00093
00094
00096
00101 function isotime($timearr){
00102 if(is_array($timearr) && $timearr['hour']!='' && $timearr['minute']!=''){
00103 $isotime=$timearr['hour'].':'.$timearr['minute'];
00104 }else{
00105 $isotime='';
00106 }
00107 return $isotime;
00108 }
00109
00110
00112
00123 function df($date="",$fmt=false){
00124 if($date){
00125 global $SQL_DATE_FMT;
00126 $date_fmts=Array("ymd","mdy","dmy");
00127 if(!in_array($SQL_DATE_FMT,$date_fmts)) $SQL_DATE_FMT="ymd";
00128 list(
00129 ${substr($SQL_DATE_FMT,0,1)},
00130 ${substr($SQL_DATE_FMT,1,1)},
00131 ${substr($SQL_DATE_FMT,2,1)}
00132 )=split('-',$date);
00133 }
00134 $tmp=$date?mktime(0,0,0,$m,$d,$y):time();
00135 $save=setlocale(LC_TIME,"it_IT");
00136 $fmtdate=strftime($fmt?$fmt:"%x",$tmp);
00137 setlocale(LC_TIME,$save);
00138 return $fmtdate;
00139 }
00140
00142
00147 function o_iftrue ($fmt,$str){
00148 if($str!=""){ return(sprintf($fmt,$str)); }
00149 }
00150
00152
00154
00155
00157
00166 function clean_exif(&$arr){
00167 if (!is_array($arr)){
00168
00169
00170 $arr=preg_replace('/[^ -\~]+/','',$arr);
00171 }
00172 else{
00173 foreach($arr as $key=>$val){
00174 clean_exif($arr[$key]);
00175 };
00176 };
00177 };
00178
00179
00181
00188 function exif_to_array($exif){
00189 if($exif){
00190 $chars = preg_split("/(^\')|(\'\=>\')|(\'\n\')|(\'\n$)/", $exif);
00191 array_shift($chars);
00192 array_pop($chars);
00193
00194 $num=count($chars);
00195 $i=0;
00196 while($i<$num){
00197 $arr_exif[$chars[$i]][$chars[$i+1]]=$chars[$i+2];
00198 $i=$i+3;
00199 };
00200 };
00201 return $arr_exif;
00202 };
00203
00205
00212 function array_to_exif($exif_array){
00213 $exif='';
00214 if($exif_array){
00215 foreach($exif_array as $key=>$section) {
00216 foreach($section as $name=>$val) {
00217 $exif.="'".addslashes($key)."'=>'".addslashes($name)."'=>'".addslashes($val)."'\n";
00218 };
00219 };
00220 };
00221 return $exif;
00222 }
00223
00224
00225 function secure_unset($name){
00226 if(isset($name)){
00227 unset($name);
00228 return true;
00229 }
00230 else return false;
00231 }
00232
00233
00234 function array_unset(&$array, $keys){
00235 if(!is_array($keys))$keys=array($keys);
00236 $new=array();
00237
00238 if(!is_array($array)) return;
00239 foreach($array as $key=>$val){
00240 if(!in_array($key, $keys)){
00241 $new[$key]=&$array[$key];
00242 }
00243 }
00244 $array=$new;
00245 }
00246
00247 function getmicrotime(){
00248 list($usec, $sec) = explode(" ",microtime());
00249 return ((float)$usec + (float)$sec);
00250 }
00251
00252 ?>