【问题标题】:split(':',$currenttime); deprecated [duplicate]拆分(':',$当前时间);已弃用 [重复]
【发布时间】:2017-08-07 16:22:35
【问题描述】:

我犯了这个错误

已弃用:函数 split() 在 list($hrs,$mins,$secs,$msecs) = split(':',$currenttime); 中已弃用

如何改写

date_default_timezone_set('US/Eastern');
$currenttime = date('h:i:s A',strtotime($row["orc15"]));
list($hrs,$mins,$secs,$msecs) = split(':',$currenttime);
$tha = date('h:i:s A',strtotime($row["orc15"]." -3 hours"));

【问题讨论】:

  • split 的替代方案列在文档中:php.net/split
  • 你阅读了PHP手册页for split()然后看红框中提到的ALTERNATIVES
  • 或者后面的TIPS同页split() is deprecated as of PHP 5.3.0. preg_split() is the suggested alternative to this function. If you don't require the power of regular expressions, it is faster to use explode(), which doesn't incur the overhead of the regular expression engine.

标签: php


【解决方案1】:

来自PHP manual

警告 此函数在 PHP 5.3.0 中已弃用,在 PHP 7.0.0 中已移除。 此功能的替代方案包括:

  • preg_split()
  • explode()
  • str_split()

explode() 可以轻松完成您想要的:

list($hrs,$mins,$secs,$msecs) = explode(':',$currenttime);

【讨论】:

    【解决方案2】:

    像这样

    list($hrs,$mins,$secs,$msecs) = explode(':',$currenttime);
    

    【讨论】:

      【解决方案3】:

      使用explode而不是split: http://php.net/manual/en/function.explode.php

      【讨论】:

        猜你喜欢
        • 2018-12-12
        • 1970-01-01
        • 2020-04-20
        • 1970-01-01
        • 2018-01-03
        • 2014-10-27
        • 2020-09-23
        • 2014-03-14
        • 2013-02-23
        相关资源
        最近更新 更多