On Sat, 2010-09-04 at 21:52 +0200, Alex Baumann wrote:
> 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!");
> >
preg_match('/PHP (.*) swesome/', 'PHP is awesome', $matches);
works nicely, we won't add special purpose functions for things that can
easily be done already.
> 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.
For parsing DOM or tidy are better.
johannes
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php