在 php 中拆分与爆炸

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3690495/
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 10:43:30  来源:igfitidea点击:

split vs. explode in php

php

提问by Tejas Patel

What is the difference between explodeand splitin php?

explodesplit在 php 中有什么区别?

回答by amphetamachine

explodesplits strings.

explode拆分字符串。

splitalso does this, except it has support for splitting using regular expressions.

split也这样做,只是它支持使用正则表达式进行拆分。

preg_splitalso does this and is 25-50% fasterand has support for (IMO) much more extensible Perl-compatible regular expressions.

preg_split也这样做,速度提高了 25-50%,并且支持 (IMO) 更可扩展的 Perl 兼容正则表达式。

回答by tamasd

splituses regular expressions, while explodeworks with delimiter characters. Using splitis discouraged, because it become deprecated in PHP 5.3.

split使用正则表达式,而explode使用分隔符。split不鼓励使用,因为它在 PHP 5.3 中已被弃用。

回答by sushil bharwani

explode is generally faster than split ; but its not multibyte character safe.

爆炸通常比分裂快;但它不是多字节字符安全的。

We will use explode when we are absolutely guaranteed that our input is in single-byte character sets such as ISO-8859-1, and split when we are dealing with user input.

当我们绝对保证输入是 ISO-8859-1 等单字节字符集时,我们将使用爆炸,并在处理用户输入时使用拆分。

回答by Kundan Sharma

Both split and explode function splits the string into the array but split is used to split a string using regular expressionwhile explode is used to split a string using another string.

split 和 expand 函数都将字符串拆分为数组,但 split 用于使用正则表达式拆分字符串,而 expand 用于使用另一个字符串拆分字符串