php取数字 本帖最后由 jaredlong 于 2014-05-31 20:33:46 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 思路:根据字符串截取年月 例如:TKPC10069999 截取得到1006再转化为时间为$newtime,再与当前时间加上5年比较,$addfiveyear = strtotime("+5 year",time())具体自己可以去试着实现if ($newtime > $addfiveyear){ echo "超过5年";} $x="TKMB15030WE5"; $year = substr($x,4,2); $month = substr($x,6,2); $tkpc = strtotime('$year-$month');$addfiveyear = strtotime("+5 year",time()); echo "$tkpc"; echo "和" ; echo "$addfiveyear";尝试失败了。$tkpc输出不了 字符串比大小,印象中应该是按字节依次比较ASCII值也就是说,TKPC10069999这种字符串不需要额外处理可以直接比较马上过节了,按2014-6-1算,用date('Ym')生成1406,减5年前后拼接成TKPC09060000,直接跟它比大小 <?php$arr = array('TKPC10069999', 'TKPC1010093A', 'TKPC12030AE3');foreach($arr as $val){ check5years($val);}echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';function check5years($str){ $year = substr($str, 4, 2); $month = substr($str, 6, 2); $tkpc = strtotime('20'.$year.'-'.$month.'-01'); echo $str.'<br>'; echo 'tkpc:'.$tkpc.'<br>'; if(strtotime("+5 year", $tkpc)<time()){ echo '超过5年'; }else{ echo '未超过5年'; } echo '<br><br>';}?> 谁跟谁比?相互比较还是与今天比?为何要转化成时间?直接化成月不更简单吗? substr($x,4,2) * 12 + substr($x,6,2); tkpc的值和当前时间的5年前比。5年内提示未满5年,超过5年提示满5年 echo $row['tkpc'], 4, 2) * 12 + $row['tkpc'], 6, 2) > (date('y') - 5) * 12 + date('m') ? '未满5年' : '满5年'; 我使用xdebug,生成的多个trace文件,哪个先生成,哪个后生成,怎么看 php6的配置文件 php四级联动的问题如何解决啊!愁啊愁! 大神求教!PHP导出大大大问题!!!加急!! 在安装论坛中遇到的问题 很多朋友回答了很多次,我想要一个例子 php如何调用oracle存储过程 帮我看看这段php代码哪里有问题吧? 一个问题啊。回答有奖 php 合成图片出错 PHP分析POST重复值 PHP配置问题
再与当前时间加上5年比较,$addfiveyear = strtotime("+5 year",time())具体自己可以去试着实现if ($newtime > $addfiveyear){
echo "超过5年";
}
$year = substr($x,4,2);
$month = substr($x,6,2);
$tkpc = strtotime('$year-$month');
$addfiveyear = strtotime("+5 year",time());
echo "$tkpc";
echo "和" ;
echo "$addfiveyear";尝试失败了。$tkpc输出不了
也就是说,TKPC10069999这种字符串不需要额外处理可以直接比较
马上过节了,按2014-6-1算,用date('Ym')生成1406,减5年前后拼接成TKPC09060000,直接跟它比大小
foreach($arr as $val){
check5years($val);
}echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';function check5years($str){
$year = substr($str, 4, 2);
$month = substr($str, 6, 2);
$tkpc = strtotime('20'.$year.'-'.$month.'-01');
echo $str.'<br>';
echo 'tkpc:'.$tkpc.'<br>';
if(strtotime("+5 year", $tkpc)<time()){
echo '超过5年';
}else{
echo '未超过5年';
}
echo '<br><br>';
}?>
相互比较还是与今天比?为何要转化成时间?
直接化成月不更简单吗?
substr($x,4,2) * 12 + substr($x,6,2);
tkpc的值和当前时间的5年前比。5年内提示未满5年,超过5年提示满5年