Re: EREG PROBLEM
| From: | Georgie Casey | Date: | Fri, 13 Sep 2002 22:55:11 +0000 |
| Subject: | Re: EREG PROBLEM | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116325@lists.php.net to get a copy of this message | ||
i thought ereg captured globally, anyway, thanks a lot, u saved me a lot of
stress
"Zak Greant" <zak@php.net> wrote in message
news:200209131628.37853.zak@php.net...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On September 13, 2002 15:59, Georgie Casey wrote:
> > input variable is as follows:
> ...
> > statement is
> > $search =
> > ereg('http://www.server.com/data/anim/(.+).gif', $input,
> > $results);
> >
> > returns the full string from 82007 onwards
>
> I bet that it captures everything up to '.." hspace="4"
> vspace="2"</a>' -- by default regular expressions in PHP are
> 'greedy' -
> they try to match as much of a pattern as possible.
>
> Also, ereg() only captures the first match for the pattern - not all
matches
> globally. To do this, use preg_match_all()
>
> preg_match_all(
> /* the ? after the + makes the match non-greedy */
> '{http://www.server.com/data/anim/(.+?).gif}',
> $input,
> $matches
> );
>
> The second element of the $matches array will contain another array that
> has all of the file name matches in it.
>
> Use var_dump($matches) to see the full contents of the array. Check the
> manual entry on preg_match_all for more information on what is going on
> in the regular expression.
>
>
> Cheers!
> --zak
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.7 (GNU/Linux)
>
> iD8DBQE9gmaUb6QONwsK8bIRAvj6AJ9Zo7smGSUHHB/u8d6sa1pOe8twiQCgjfO6
> PydHz4u1tuF/Oc9qxItp8bQ=
> =ilHI
> -----END PGP SIGNATURE-----
>