String get between

Returns the content between $start and $end

Snippet information

Author:
Jonas

License:
Public Domain

Language:
PHP

Created:
03/28/2006

Updated:
03/28/2006

Tags:
,


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


Found a bug? Or do you have a better solution for this?
Feel free to leave a message:

Add a comment


Leave a comment

Andrei Gherasim June 07, 2010 at 20:57
substr(string $string, int $start [, int $length) does the same thing. And it should be lot faster, as it's a core function. http://php.net/manual/en/function.substr.php
sks March 19, 2010 at 14:02
it helps me lot..
thank u..
ddx August 13, 2009 at 12:47
useful
NONAME December 07, 2008 at 14:48
Thanks.