Tuesday 23 January 2018

String get between

Returns the content between $start and $end

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

// --> returns ' test ';

0 comments:

Post a Comment