The code below shows an example of how to parse a phrase to get a string that is between two strings with PHP.
The Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php 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); } $phrase = "the quick brown fox jumped over the lazy dog"; echo get_string_between($phrase, 'the quick brown ', ' jumped over the lazy dog'); //this prints out 'fox' ?> |