user3304007 user3304007 - 1 month ago 8x
PHP Question

My GetBetween function need to get multiple results

I have been using this function to get content between tags, because its faster than preg_match_all (almost 100 queries once).

function GetBetween($content,$start,$end){
$r = explode($start, $content);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
return '';

$content = ",john,,benny,,steven,gerard,";
$usercount = substr_count($content,",") / 2;

for ($t=0;$t<$usercount;$t++)

$users = GetBetween($content,",",",");
echo $users


However, it just gives me one result. Which method should I use to get all results ?


To just get all words between commas(as separators) use the following simple approach with explode and array_filter functions:

$content = ",john,,benny,,steven,gerard,";
$words = array_filter(explode(",", $content));
// now you can easily iterate through $words array outputting each word

The output:

    [1] => john
    [3] => benny
    [5] => steven
    [6] => gerard