Hi!
Since I'm using this function in each project I'm working on, how about
making it a built-in function?
function between ($text, $between, $and) {
$start = strpos($text, $between)+strlen($between);
if ($start === false) return "";
$end = strpos($text, $and, $start);
if ($end === false) return "";
return substr($text, $start, $end-$start);
}
Basicly this function returns a substring given in a text $text between
two strings, $between and $and, occuring in $text.
Here are some examples:
echo between("PHP is awesome!", "PHP ", " awesome!");
> is
echo between("PHP is awesome!", "P", "o");
> HP is awes
echo between("PHP is awesome!", "PHP ", "great!");
>
As mentioned above, this function is very useful, for example when
parsing formated input data like html files, and everyone I told about
it adopted it and is very thankful.
Thanks,
Alex
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php