PHP 中的“函数 split() 已弃用”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5699137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:16:11  来源:igfitidea点击:

"Function split() is deprecated" in PHP?

phparraysstringsplit

提问by chrithccmc

$stringText = "[TEST-1] test task 1 Created: 06/Apr/11  Updated: 06/Apr/11"; 
$splitArray = split(" ",$stringText);

Deprecated: Function split() is deprecated in C:\wamp\www\RSS.php on line 27

已弃用:函数 split() 在 C:\wamp\www\RSS.php 中的第 27 行已弃用

Why this error happen ?

为什么会发生这个错误?

回答by JohnP

http://php.net/manual/en/function.split.php

http://php.net/manual/en/function.split.php

From the manual

从手册

Warning This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged

Note:

As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED notice. See the list of differences for help on converting to PCRE.

警告 该函数自 PHP 5.3.0 起已被弃用。非常不鼓励依赖此功能

笔记:

从 PHP 5.3.0 开始,regex 扩展已被弃用,取而代之的是 PCRE 扩展。调用此函数将发出 E_DEPRECATED 通知。有关转换为 PCRE 的帮助,请参阅差异列表。

I guess you're supposed to use the alternative preg_split(). Or if you're not using a regex, just use explode

我猜你应该使用替代preg_split(). 或者,如果您不使用正则表达式,请使用explode

回答by gnur

split has been replaced with explode, see http://php.net/explodefor more information. Works the same as split, but split is 'deprecated' basically means that is a old function that shouldn't be used anymore, and is not likely to be in later versions of php.

split 已替换为explode,请参阅http://php.net/explode了解更多信息。与 split 的工作原理相同,但 split 已“弃用”基本上意味着它是一个不应再使用的旧函数,并且不太可能出现在更高版本的 php 中。

回答by Pritam Chaudhari

Use following explode function:

使用以下爆炸函数:

$command = explode(" ", $tag[1]);

This is the standard solution for this case. Its Perfectly working.

这是这种情况的标准解决方案。它完美地工作。

回答by Janis Veinbergs

Ahh, the docssays about it. And the docs also say which functions should be used instead of this:

啊,文档是这么说的。并且文档还说明应该使用哪些函数而不是这个:

  1. preg_split
  2. explode
  3. str_split
  1. preg_split
  2. 爆炸
  3. str_split

回答by Jim W.

Because the function has been deprecated? You can customize the error_reporting level to not log / display the depreciated errors. But it would be more prudent to just correct the issue (IE use explode instead for the simple split you are doing above.)

因为该功能已被弃用?您可以自定义 error_reporting 级别以不记录/显示折旧错误。但是,仅更正问题会更加谨慎(IE 使用爆炸代替您在上面所做的简单拆分。)