爆炸不返回空字符串? [英] Explode that doesn't return empty strings?
本文介绍了爆炸不返回空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PHP的explode函数返回在提供的某些子字符串上拆分的字符串数组.它将返回空字符串,如下所示:
PHP's explode function returns an array of strings split on some provided substring. It will return empty strings like this:
var_dump(explode('/', '1/2//3/'));
array(5) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(0) ""
[3]=>
string(1) "3"
[4]=>
string(0) ""
}
是否有一些不同的函数或选项,或者会返回除空字符串以外的所有内容的?
Is there some different function or option or anything that would return everything except the empty strings?
var_dump(different_explode('/', '1/2//3/'));
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "3"
}
推荐答案
尝试 preg_split .
$exploded = preg_split('@/@', '1/2//3/', NULL, PREG_SPLIT_NO_EMPTY);
这篇关于爆炸不返回空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文