/** * Search a string for a substring between $start and $end substrings */ function get_string_between($string, $start, $end, $inclusive = FALSE) { /* for convenience, we make our string start at position #1 */ $string = ' ' . $string; $string = htmlentities($string); $start = htmlentities($start); $end = htmlentities($end); /* initial point = position of start delimiter */ $ini = strrpos($string, $start); /* if start not found, return null */ if ($ini == 0) { return ""; } /* the actual initial point should just after the start delimiter */ $ini += strlen($start); /* the length of the string we're seeking * is distance between the start and end delimiters, minus the start delimiter's length */ $len = strrpos($string, $end, $ini) - $ini; /* if "inclusive" then tack the delims onto the found string */ $ret = substr($string, $ini, $len); if ($inclusive) { $ret = $start . $ret . $end; } return html_entity_decode($ret); }