已弃用:函数 split() 已弃用。如何重写这个语句?

发布于 2024-09-14 03:42:02 字数 406 浏览 3 评论 0原文

我有以下语句,在 PHP 5.3 之前使用 split 函数 运行良好:

list($year, $month, $day, $hour, $min, $sec) = split( '[: -]', $post_timestamp );

升级后到 PHP 5.3,我收到“已弃用”警告:

已弃用:函数 split() 已弃用。

我正在尝试解析格式如下的字符串:

2010-08-10 23:07:58

进入其组成部分。

I have the following statement which worked fine before PHP 5.3 using the split function:

list($year, $month, $day, $hour, $min, $sec) = split( '[: -]', $post_timestamp );

After upgrading to PHP 5.3, I get the Deprecated warning:

Deprecated: Function split() is deprecated.

I am trying to parse a string with format like:

2010-08-10 23:07:58

into its component parts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

jJeQQOZ5 2024-09-21 03:42:02

我想你想要 preg_split

list($year, $month, $day, $hour, $min, $sec) = preg_split('/[: -]/', $post_timestamp);

I think you want preg_split.

list($year, $month, $day, $hour, $min, $sec) = preg_split('/[: -]/', $post_timestamp);
流心雨 2024-09-21 03:42:02
$dateTime = new DateTime('2010-08-10 23:07:58');

$year = $dateTime->format('Y');
$month = $dateTime->format('m');

你得到钻...
根据您要使用它执行的操作,使用 DateTime 对象可能比使用六个单独的变量更方便。

$dateTime = new DateTime('2010-08-10 23:07:58');

$year = $dateTime->format('Y');
$month = $dateTime->format('m');

You get the drill...
Depending, on what you're going to do with it, using DateTime object might be more convenient than using six separate variables.

愁杀 2024-09-21 03:42:02

只需尝试用“explode”替换“split”即可,较新版本的 PHP 和 MYSQL 接受“explode”而不是“split”

Just try to replace "split" with "explode" the newer version of PHP and MYSQL accept "explode" instead of "split"

情泪▽动烟 2024-09-21 03:42:02
var_dump(strptime($post_timestamp, '%Y-%m-%d %H:%M:%S'));
var_dump(strptime($post_timestamp, '%Y-%m-%d %H:%M:%S'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文