A little but useful function to get text between two specified strings.
It takes three parameters. The source, start and end. And returns the text between start and end delimeters.
Example
$str="This is my content from which i want to fetch a block of text between two delimeters. Note that it returns only the first match";
echo between($str, "my", "returns");
It takes three parameters. The source, start and end. And returns the text between start and end delimeters.
function between($src,$start,$end){
$txt=explode($start,$src);
$txt2=explode($end,$txt[1]);
return trim($txt2[0]);
}
Example
$str="This is my content from which i want to fetch a block of text between two delimeters. Note that it returns only the first match";
echo between($str, "my", "returns");
Posting Komentar