Get the text between $start and $end

Submitted by:Jhon Jhon

Date added:24 July, 2012

Category:PHP

This is the kind of function every web developer should have in their toolbox for future use: give it a string, a start, and an end, and it will return the text contained with $start and $end.

Tags: php function

Code Snippet:

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

Comments