duane2364 2014-11-07 11:19
浏览 14
已采纳

通过命令行将日期传递给PHP

I want to be able to run a script via the command line and pass it a date for a function.

How would I go about doing this? I.e I need to pass it to a function within the file and pass it a typed date in the format. YYYY-MM-DD HH-MM Where the second MM is minutes not Month.

Would I need to use particular flags in the command or is there a simpler way?

  • 写回答

1条回答 默认 最新

  • duanrong6802 2014-11-07 11:21
    关注

    Why don't you use:

    $date = date("Y-m-d H:i:s");
    

    in your script?

    Edit:

    If you want to catch a parameter, you should use $argv array:

    if (!isset($argv[1])) {
       die("You should give a date as first parameter
    ");
    }
    if (!@strtotime($argv[1])) {
       die("The date you given is invalid.
    ");
    }
    $date = $argv[1];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 OpenGL渲染效率
  • ¥60 关于网络前后端:丢包攻击、漏洞后门、渗透这些
  • ¥30 有关于html的制作个人网页
  • ¥15 stm32 lvgl+DMA,屏幕显示不全有条纹
  • ¥15 用java,swing,mysql实现模拟ATM机系统
  • ¥15 HTML5+CSS3题
  • ¥30 使用php如何制作一个国博门票抢票系统?(相关搜索:手机号|小程序)
  • ¥15 关于#数据库#的问题:每次实验都是系统直接导出数据,但是实验过程前会修改被实验件的结构类型,软件版本(如第一次实验为结构A,A01版本软件,A01版本软件)(相关搜索:数据类型)
  • ¥15 群晖docker无法连接代理服务器
  • ¥20 VBA将EXCEL数据写入JSON,中文不显示