PHP Get All Strings between Start and end

There are lots of resources on the web, but I could not get any to work properly. So, I’ve written my own as simply as possible:

function get_all_strings_between($string, $start, $end){
   $res=array();
   $tmp=explode($start,$string);
   $c=count($tmp);
   for($i=1;$i<$c;$i++){
      $v=$tmp[$i];
      if(strrpos($v,$end)!==false){
         $tmp1=explode($end,$v);
         if(count($tmp1)>1){
            $res[]=$tmp1[0];
         }
      }
   }
   return $res;
}

Leave a Reply