douke9379 2014-06-16 19:31
浏览 30
已采纳

从现在开始使用PHP,我怎样才能回复日期?

I am making a script that will allow admins to ban IPs. I am currently implementing the ban length system, however I am trying to echo the lift date next to each select option.

Here is my HTML for the dropdown select:

             <strong>Select Ban Length</strong>
       <div class="select-style">
  <select>
    <optgroup label="Temporary Ban Options">
    <option value="1">1 Day</option>
    <option value="3">3 Days</option>
    <option value="7">7 Days</option>
    <option value="14">14 Days</option>
    </optgroup>
    <optgroup label="Permanent Ban Options">
      <option value="PERMANENT">Permanent - Never Lift Ban</option>
    </optgroup>
  </select>
</div>

What I am asking is how can I echo the lift date next to each item? For example:

enter image description here

I have started with <?php echo date('Y-m-d H:i:s'); ?> to get the current date but how can I, as shown in the image above achieve something similar where the lift date is beside the ban length?

  • 写回答

3条回答 默认 最新

  • duanrongpai9556 2014-06-16 19:36
    关注

    You would use strtotime's automatic + n days ability using this date string m-d-Y H:i A to give what you asked for in your example image.

    <strong>Select Ban Length</strong>
    <div class="select-style">
      <select>
        <optgroup label="Temporary Ban Options">
        <?php
        foreach (array(1, 3, 7, 14) as $d){
            // setting $date and $text separately just for readability here
            $text = $d . ' Day' . ($d===1? '': 's');
            $date = date('m-d-Y H:i A', strtotime('+ ' . $d .' days'));
            echo '<option value="'.$d.'">' . $text . ' (' . $date . ')</option>';
        }
        ?>
        </optgroup>
        <optgroup label="Permanent Ban Options">
          <option value="PERMANENT">Permanent - Never Lift Ban</option>
        </optgroup>
      </select>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 R语言 拟时序分析降维图如何减少分支
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统