首页 > 编程技术 > php

php 读写缓存文件实例 var_export

发布时间:2016-11-25 15:59

 代码如下 复制代码
function read_static_cache($cache_name) { static $result = array(); if (!empty($result[$cache_name])) { return $result[$cache_name]; } $cache_file_path = 'E:/newWeb/web/test/temp/static_caches/' . $cache_name . '.php'; if (file_exists($cache_file_path)) { include_once($cache_file_path); $result[$cache_name] = $data; return $result[$cache_name]; } else { return false; } } /** * 写结果缓存文件 * * @params string $cache_name * @params string $caches * * @return */ function write_static_cache($cache_name, $caches) { $cache_file_path = 'E:/newWeb/web/test/temp/static_caches/' . $cache_name . '.php'; $content = ""; file_put_contents($cache_file_path, $content, LOCK_EX); } function load_config(){ $data = array(); $data = read_static_cache('shop_config'); if ($data === false){ $rs = Execute('SELECT * FROM size WHERE 1'); while($row=FetchArray($rs)){ $data[$row['sizeID']]['sizeNamec'] = $row['sizeNamec']; $data[$row['sizeID']]['sizeNamee'] = $row['sizeNamee']; $data[$row['sizeID']]['sindex'] = $row['sindex']; } write_static_cache('shop_config', $data); } else{ $data = $data; } return $data; } $data = load_config();

 

日期与时间函数库{经常会忘却掉}
checkdate : 验证日期的正确性。
date : 将服务器的时间格式化。
strftime : 将服务器的时间本地格式化。
getdate : 获得时间及日期信息。
gettimeofday : 取得目前时间。
gmdate : 取得目前与 GMT 差后的时间。
easter_date : 计算复活节日期。
easter_days : 计算复活节与三月廿一日之间日期数。
mktime : 取得 UNIX 时间戳记。
gmmktime : 取得 UNIX 时间戳记的格林威治时间。
time : 取得目前时间的 UNIX 时间戳记。
microtime : 取得目前时间的 UNIX 时间戳记的百万分之一秒值。

  checkdate 验证日期的正确性。
语法: int checkdate(int month, int day, int year);
返回值: 整数
函数种类: 时间日期
内容说明 若日期是有效的则返回 true,若日期有问题,则返回 false。本函数可以用来检查日期是否有效。有效范围如下:
年 为 0 至 32767 年
月 为 1 至 12 月
日 则随着月份及闰年变化
date 将服务器的时间格式化。
语法: string date(string format, int [timestamp]);
返回值: 字符串
函数种类: 时间日期
内容说明返回值的?字符串依配置的格式来决定。若有传入时间戳记值,则将时间戳记格式化返回;若无传入时间戳记值,则将目前服务器的时间格式化返回。要将日期转为其它的语系格式,应使用setlocale() 及 strftime() 二个函数。字符串格式化的选项如下:
a - "am" 或是 "pm"
A - "AM" 或是 "PM"
d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31"
D - 星期几,三个英文字母; 如: "Fri"
F - 月份,英文全名; 如: "January"
h - 12 小时制的小时; 如: "01" 至 "12"
H - 24 小时制的小时; 如: "00" 至 "23"
g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12"
G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23"
i - 分钟; 如: "00" 至 "59"
j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31"
l - 星期几,英文全名; 如: "Friday"
m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12"
n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12"
M - 月份,三个英文字母; 如: "Jan"
s - 秒; 如: "00" 至 "59"
S - 字尾加英文序数,二个英文字母; 如: "th","nd"
t - 指定月份的天数; 如: "28" 至 "31"
U - 总秒数
w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)
Y - 年,四位数字; 如: "1999"
y - 年,二位数字; 如: "99"
z - 一年中的第几天; 如: "0" 至 "365"
其它不在上列的字符则直接列出该字符。
使用范例,范例一:
<?
print(date( "l dS of F Y h:i:s A" ));
print("July 1, 2000 is on a " . date("l", mktime(0,0,0,7,1,2000)));
?>

  范例二:
<?
$tomorrow = mktime(0,0,0,date("m") ,date("d")+1,date("Y"));
$lastmonth = mktime(0,0,0,date("m")-1,date("d"), date("Y"));
$nextyear = mktime(0,0,0,date("m"), date("d", date("Y")+1);
?>

  参考 gmdate() mktime()
strftime 将服务器的时间本地格式化。
语法: string strftime(string format, int [timestamp]);
返回值: 字符串
函数种类: 时间日期
内容说明返回值的字符串依配置的格式来决定。若有传入时间戳记值,则将时间戳记格式化返回;若无传入时间戳记值,则将目前服务器的时间本地格式化返回。月份或者星期名称随着本地语系配置 setlocale() 的不同而改变。
返回的字符串可以依下列的格式而定:
%a 星期几的缩写。
%A 星期几的全名。
%b 月份名称的缩写。
%B 月份名称的全名。
%c 本地端日期时间较佳表示字符串。
%d 用数字表示本月的第几天 (范围为 00 至 31)。
%H 用 24 小时制数字表示小时数 (范围为 00 至 23)。
%I 用 12 小时制数字表示小时数 (范围为 01 至 12)。
%j 以数字表示当年度的第几天 (范围为 001 至 366)。
%m 月份的数字 (范围由 1 至 12)。
%M 分钟。
%p 以 'AM' 或 'PM' 表示本地端时间。
%S 秒数。
%U 数字表示为本年度的第几周,第一个星期由第一个周日开始。
%W 数字表示为本年度的第几周,第一个星期由第一个周一开始。
%w 用数字表示本周的第几天 ( 0 为周日)。
%x 不含时间的日期表示法。
%X 不含日期的时间表示法。
%y 二位数字表示年份 (范围由 00 至 99)。
%Y 完整的年份数字表示,即四位数。
%Z 时区或名称缩写。
%% % 字符。
使用范例
<?php
setlocale ("LC_TIME", "C");
print(strftime("%A in Finnish is "));
setlocale ("LC_TIME", "fi");
print(strftime("%A, in French "));
setlocale ("LC_TIME", "fr");
print(strftime("%A and in German "));
setlocale ("LC_TIME", "de");
print(strftime("%A.n"));
?>

$fangId = PostGet('houseId'); // 取得地址栏值
 $tempArray = array_filter(explode('_',$fangId),"filter"); //以__分成数组并且删除空数组
 
 if( is_array($tempArray) && !empty( $tempArray ) ) //判断数组是否有值
 {
  print_r($tempArray); //测试输出
 }
 else
 {
  MessAge('请选择对比较楼盘','list.php');
 }
 
 /*
 function filter($var)  处理函数
 {
   if($var == '')
   {
    return false;
   } 
   return true;
 }
 */

 

测试方法:/compare.php?houseId=2306__2307__2303__2308


方法二

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;
}

 

<?php
function BigEndian2Int($byte_word, $signed = false) {
$int_value = 0;
$byte_wordlen = strlen($byte_word);
for ($i = 0; $i < $byte_wordlen; $i++) {
$int_value += ord($byte_word{$i}) * pow(256, ($byte_wordlen - 1 - $i));
}
if ($signed) {
$sign_mask_bit = 0x80 << (8 * ($byte_wordlen - 1));
if ($int_value & $sign_mask_bit) {
$int_value = 0 - ($int_value & ($sign_mask_bit - 1));
}
}
return $int_value;
}
function getTime($name){
if(!file_exists($name)){
echo "文件不存在";exit;
}
$flv_data_length=filesize($name);
$fp = @fopen($name, 'rb');
$flv_header = fread($fp, 5);
fseek($fp, 5, SEEK_SET);
$frame_size_data_length =BigEndian2Int(fread($fp, 4));
$flv_header_frame_length = 9;
if ($frame_size_data_length > $flv_header_frame_length) {
fseek($fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR);
}
$duration = 0;
while ((ftell($fp) + 1) < $flv_data_length) {
$this_tag_header = fread($fp, 16);
$data_length = BigEndian2Int(substr($this_tag_header, 5, 3));
$timestamp = BigEndian2Int(substr($this_tag_header, 8, 3));
$next_offset = ftell($fp) - 1 + $data_length;
if ($timestamp > $duration) {
$duration = $timestamp;
}
fseek($fp, $next_offset, SEEK_SET);
}
fclose($fp);
return $duration;
}
if($_GET['submit'])
{
echo date('i分s秒',getTime($_GET['filepath'])/1000);
}
?>

<form action="" method="get">
<input type="text" size="40" value="" name="filepath">
<input type="submit" value="提交" name="submit">
</form>

<?php
function get_ip_place(){
$ip=file_get_contents("http://fw.qq.com/ipaddress");

$ip=str_replace('"',' ',$ip);

$ip2=explode("(",$ip);

$a=substr($ip2[1],0,-2);

$b=explode(",",$a);

return $b;
}


$ip=get_ip_place();


print_r($ip);
?>

标签:[!--infotagslink--]

您可能感兴趣的文章: