+ -
当前位置:首页 → 问答吧 → php判断unix时间戳大小问题

php判断unix时间戳大小问题

时间:2011-11-23

来源:互联网

一段内容加了function要做的判断就是判断这段内容最后的数字是否大于系统当前的unix时间戳

例如

标题(标题内容不是固定的) <span>1324570103</span>

这段内容就是提取<span>里的unix时间戳和当前系统的unix时间戳比较,判断大小,比时间戳大的则返回,否则不显示

我知道是return "$str" 和return" "

但是中间的判断还请高手帮忙分析下

作者: d7898585   发布时间: 2011-11-23

PHP code
function getContent($source){
   if(empty($source)) return "";
   $str = "这是我要返回的值了";
   preg_match('/<span>(\d+)<\/span>/isU',$source,$matches);
   if($matches[1]>time()){
      return $str;
   }else{
      return "";
   }
}

//使用方法
date_default_timezone_set("Asia/shanghai");
$content ='<span>1324570103</span>';
$res = getContent($content);

作者: ohmygirl   发布时间: 2011-11-23

同意楼上的方法

作者: taoliujun   发布时间: 2011-11-23

引用 1 楼 ohmygirl 的回复:

PHP code
function getContent($source){
if(empty($source)) return "";
$str = "这是我要返回的值了";
preg_match('/<span>(\d+)<\/span>/isU',$source,$matches);
if($matches[1]>time()){
return $st……

+1 其实这个 思路明确了没什么的 先理清业务逻辑再自己想

作者: JustBeBetter   发布时间: 2011-11-23

相关阅读 更多