split()
的PHP手册指出:
自从PHP 5.3.0起,此函数已弃用。强烈不建议使用此功能...请使用
explode()
代替。
但我找不到split()
和explode()
之间的区别。 join()
没有被弃用,那是为什么呢?
这个函数被弃用了,因为
explode()
更快,因为它不是基于正则表达式进行分割的,所以字符串不必经过正则表达式解析器的分析。preg_split()
更快,使用 PCRE 正则表达式进行分割。join()
和 implode()
是彼此的别名,因此没有任何区别。
split
使用正则表达式,而explode
使用固定字符串。如果您确实需要正则表达式,请使用preg_split
,它使用PCRE(现在是PHP标准库中首选的正则表达式包)。
这两个函数都用于分割字符串。
然而,Split 函数使用正则表达式来分割字符串。
另一方面,Explode 函数使用另一个字符串来分割字符串。
例如 explode(" this", "this is a string"); 将返回 "is a string"。
例如 Split(" + ", "This+ is a string");
这两个函数都用于将字符串分割成数组,但区别在于split()
使用模式进行分割,而explode()
使用字符串进行分割。explode()
比split()
更快,因为它不基于正则表达式匹配字符串。
split()
函数使用正则表达式将字符串拆分为数组并返回数组。
explode()
函数按字符串拆分字符串。
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);
?>
结果将会是
Array ( [0] => I [1] => P [2] => S )
Array ( [0] => I [1] => P [2] => S )
$explode_array=split('and','I and P and S');
这行代码也使用了 split() 函数... - O Genthe