Right below lies a function that returns the string between two other strings. That’s it.
1 2 3 4 5 6 7 8 9 10 11 12 |
function get_string_between($string, $start, $end){ $string = ' ' . $string; $ini = strpos($string, $start); if ($ini == 0) return ''; $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; return substr($string, $ini, $len); } // USAGE $fullstring = 'this is my [tag]dog[/tag]'; $parsed = get_string_between($fullstring, '[tag]', '[/tag]'); |
Source : http://stackoverflow.com/questions/5696412/get-substring-between-two-strings-php