Php 我的GetBetween函数需要获得多个结果
我一直在使用这个函数来获取标签之间的内容,因为它比preg\u match\u all(几乎100次查询)更快 函数GetBetween($content,$start,$end){ $r=分解($start,$content); 如果(isset($r[1])){ $r=爆炸($end,$r[1]); 返回$r[0]; } 返回“”; } $content=“,约翰,本尼,史蒂文,杰拉德,”; $usercount=substr\u count($content,“,”)/2;Php 我的GetBetween函数需要获得多个结果,php,Php,我一直在使用这个函数来获取标签之间的内容,因为它比preg\u match\u all(几乎100次查询)更快 函数GetBetween($content,$start,$end){ $r=分解($start,$content); 如果(isset($r[1])){ $r=爆炸($end,$r[1]); 返回$r[0]; } 返回“”; } $content=“,约翰,本尼,史蒂文,杰拉德,”; $usercount=substr\u count($content,“,”)/2; 对于($t=0
对于($t=0;$t要仅获取逗号之间的所有字(作为分隔符),请使用以下带有
explode
和array\u filter
函数的简单方法:
$content = ",john,,benny,,steven,gerard,";
$words = array_filter(explode(",", $content));
// now you can easily iterate through $words array outputting each word
print_r($words);
输出:
Array
(
[1] => john
[3] => benny
[5] => steven
[6] => gerard
)
如果您想获得快速帮助-显示输入数据和预期结果
GetBetween
函数有一个奇怪且过于复杂的逻辑。为什么?您只想获得逗号之间的所有单词,对吗?正确,那么有更好的选项吗?
Array
(
[1] => john
[3] => benny
[5] => steven
[6] => gerard
)