在 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
split vs. explode in php
提问by Tejas Patel
What is the difference between explode
and split
in php?
explode
和split
在 php 中有什么区别?
回答by amphetamachine
explode
splits strings.
explode
拆分字符串。
split
also does this, except it has support for splitting using regular expressions.
split
也这样做,只是它支持使用正则表达式进行拆分。
preg_split
also 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
split
uses regular expressions, while explode
works with delimiter characters. Using split
is 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 用于使用另一个字符串拆分字符串。