split()和explode()有什么区别?
split()
的 PHP 手册说
此函数已被弃用为 PHP 5.3.0 的版本。依靠这个功能 非常不鼓励...使用
explode()
相反。
但我找不到 split()
和 explode()
之间的区别。 join()
尚未被弃用,那么会带来什么呢?
The PHP manual for split()
says
This function has been DEPRECATED as
of PHP 5.3.0. Relying on this feature
is highly discouraged...Useexplode()
instead.
But I can't find a difference between split()
and explode()
. join()
hasn't been deprecated, so what gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
它已被弃用,因为
explode()
速度要快得多,因为它不会基于正则表达式进行拆分,因此字符串不必由正则表达式解析器进行分析preg_split()< /code> 速度更快,并且使用 PCRE 正则表达式进行正则表达式拆分
join()
和implode()
是彼此的别名,因此没有任何差异。It's been deprecated because
explode()
is substantially faster because it doesn't split based on a regular expression, so the string doesn't have to be analyzed by the regex parserpreg_split()
is faster and uses PCRE regular expressions for regex splitsjoin()
andimplode()
are aliases of each other and therefore don't have any differences.split
使用正则表达式,而explode
使用固定字符串。如果您确实需要正则表达式,请使用preg_split
,它使用 PCRE(现在 PHP 标准库中首选的正则表达式包)。split
uses regex, whileexplode
uses a fixed string. If you do need regex, usepreg_split
, which uses PCRE (the regex package now preferred across the PHP standard library).这两个函数都用于分割字符串。
但是,Split 用于使用正则表达式分割字符串。
另一方面,Explode 用于使用另一个字符串来分割一个字符串。
例如explode("this","这是一个字符串");会返回“是一个字符串”
例如 Split(" + ", "This+是一个字符串");
Both the functions are used to Split a string.
However, Split is used to split a string using a regular expression.
On the other hand, Explode is used to split a string using another string.
E.g explode (" this", "this is a string"); will return “Is a string”
E.g Split (" + ", "This+ is a string");
在
split()
中,您可以使用正则表达式来拆分字符串。而explode()
将一个字符串与一个字符串分开。如果您需要正则表达式, preg_split 是一个更快的替代方案。
In
split()
you can use regular expressions to split a string. Whereasexplode()
splits a string with a string.preg_split is a much faster alternative, should you need regular expressions.
两者都用于将字符串拆分为数组,但不同之处在于
split()
使用模式进行拆分,而explode()
使用字符串。explode()
比split()
更快,因为它不根据正则表达式匹配字符串。Both are used to split a string into an array, but the difference is that
split()
uses pattern for splitting whereasexplode()
uses string.explode()
is faster thansplit()
because it doesn't match string based on regular expression.split()
函数使用正则表达式将字符串拆分为数组并返回一个数组。explode()
函数按字符串拆分字符串。例如:
结果将是
注意:函数 split() 在 PHP 5.3.0 中已弃用,在 PHP 7.0.0 中已删除
The
split()
function splits the string into an array using a regular expression and returns an array.The
explode()
function splits the string by string.E.g:
The result will be
Note:The function split() was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0