split()和explode()有什么区别?

发布于 2024-09-17 20:13:19 字数 355 浏览 4 评论 0原文

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...Use explode()
instead.

But I can't find a difference between split() and explode(). join() hasn't been deprecated, so what gives?

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

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

发布评论

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

评论(6

美人迟暮 2024-09-24 20:13:19

它已被弃用,因为

  • 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 parser
  • preg_split() is faster and uses PCRE regular expressions for regex splits

join() and implode() are aliases of each other and therefore don't have any differences.

柳絮泡泡 2024-09-24 20:13:19

split 使用正则表达式,而 explode 使用固定字符串。如果您确实需要正则表达式,请使用 preg_split ,它使用 PCRE(现在 PHP 标准库中首选的正则表达式包)。

split uses regex, while explode uses a fixed string. If you do need regex, use preg_split, which uses PCRE (the regex package now preferred across the PHP standard library).

小情绪 2024-09-24 20:13:19

这两个函数都用于分割字符串。

但是,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");

陌路黄昏 2024-09-24 20:13:19

split()中,您可以使用正则表达式来拆分字符串。而 explode() 将一个字符串与一个字符串分开。
如果您需要正则表达式, preg_split 是一个更快的替代方案。

In split() you can use regular expressions to split a string. Whereas explode() splits a string with a string.
preg_split is a much faster alternative, should you need regular expressions.

策马西风 2024-09-24 20:13:19

两者都用于将字符串拆分为数组,但不同之处在于 split() 使用模式进行拆分,而 explode() 使用字符串。 explode()split() 更快,因为它不根据正则表达式匹配字符串。

Both are used to split a string into an array, but the difference is that split() uses pattern for splitting whereas explode() uses string. explode() is faster than split() because it doesn't match string based on regular expression.

丑疤怪 2024-09-24 20:13:19

split() 函数使用正则表达式将字符串拆分为数组并返回一个数组。

explode() 函数按字符串拆分字符串。

例如:

<?php
    $split_array=split(':','I:P:S');
    $explode_array=explode('and','I and P and S');
    print_r($split_array);
    print_r($explode_array);
?>

结果将是

Array ( [0] => I [1] => P [2] => S ) 
Array ( [0] => I [1] => P [2] => S )

注意:函数 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:

<?php
    $split_array=split(':','I:P:S');
    $explode_array=explode('and','I and P and S');
    print_r($split_array);
    print_r($explode_array);
?>

The result will be

Array ( [0] => I [1] => P [2] => S ) 
Array ( [0] => I [1] => P [2] => S )

Note:The function split() was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文