Get a String Between a Substring and the End of a String

Get a String Between a Substring and the End of a String

Here is a custom PHP script I wrote that works if you need a string that is between a substring and the end of a string.

function between($text, $start){
     $string = substr($text, strpos($text, $start));
     return str_replace($start, " ", $string); 
}

Let’s say that you have a URL “http://en.wikipedia.org/wiki/Pensacola” and you need the relative path of the article (Pensacola).

return between("http://en.wikipedia.org/wiki/Pensacola", "wiki/");
 //Returns Pensacola

 

Leave a Reply