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 '';
Snippet Details

GetBetween('foo test bar', 'foo', 'bar');
// --> returns ' test ';

Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!

Older comments:

Tahir July 08, 2011 at 08:49
Thanks dude, keep it up. This helped me alot
Daniel April 03, 2011 at 01:18
How do I get a string between a substring and the end of the content?
Axel March 19, 2011 at 07:30
Thanks for this! Helped me greatly!
Mette January 19, 2011 at 15:55
I have a search engine on my homepage. I am looking for at script to search between product prices.
Where to find?

Mette January 19, 2011 at 15:54
I have a search engine on my homepage and I am looking for a script, so I can search between my product prices
Where to find?
Defoe October 23, 2010 at 16:26
> Andrei Gherasim
Really? It does the same? Read carefully...
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.
sks March 19, 2010 at 14:02
it helps me lot..
thank u..
ddx August 13, 2009 at 12:47
NONAME December 07, 2008 at 14:48