Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的GetBetween函数需要获得多个结果_Php - Fatal编程技术网

Php 我的GetBetween函数需要获得多个结果

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

我一直在使用这个函数来获取标签之间的内容,因为它比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要仅获取逗号之间的所有字(作为分隔符),请使用以下带有
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
)