douwu5009 2018-07-09 04:55
浏览 11

Php,date_modify()带变量

I need to use the indexed element as the amount to change the date by

$id = $_POST['id'];
$ids = explode(',',$id);

$dateCreated = date('Y-m-d'); 
$dateExpiredtemp =date_create($dateCreated);
date_modify($dateExpiredtemp,'+ $ids[2]'); 
$dateExpired = date('$dateExpiredtemp');

date_modify($dateExpiredtemp,'+ $ids[2]');

This line provides this error

Warning: date_modify(): Failed to parse time string (+ $ids[2]) at position 0 (+): Unexpected character in

$ids[2] is a string and it needs to be carried into the altering parameter of date_modify

  • 写回答

2条回答 默认 最新

  • douan2907 2018-07-09 05:02
    关注

    Change this line of code

    date_modify($dateExpiredtemp,'+ $ids[2]');
    

    into

    date_modify($dateExpiredtemp,'+ ' . $ids[2]);
    

    Your initial code will not recognize the $ids[2] since it is included in the string. Therefore, $ids[2] won't be parsed.

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?