PHP and javascript snippets you can copy and paste.

Saturday, March 31, 2007

str_get_textBetween($start,$end,$str)

/**
* Gets the text between two points in a string.
* @param int $start.
* @param int $end.
* @param string $str - string to remove quotes from.
* @return string.
*/

function str_get_textBetween($start,$end,$str){
$toMatch = "/" . $start . "(.*?)" . $end . "/";
preg_match($toMatch,$str,$matches);
return isset($matches[1])?$matches[1]:'';
}

No comments: