RE: [PHP] preg_match_all()
| From: | John W. Holmes | Date: | Tue, 04 Mar 2003 01:23:09 +0000 |
| Subject: | RE: [PHP] preg_match_all() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138008@lists.php.net to get a copy of this message | ||
Use a U modifier in your pattern.
http://www.php.net/manual/en/pcre.pattern.modifiers.php
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/
> -----Original Message-----
> From: Vania Smrkovski [mailto:vania@pandorasdream.com]
> Sent: Monday, March 03, 2003 7:51 PM
> To: php-general@lists.php.net
> Subject: [PHP] preg_match_all()
>
> As described in
http://www.php.net/manual/en/function.preg-match-all.php,
> I
> have put in place a bit of code theoretically designed to parse out
> snippets
> of text embraced with an open and close tag. The code I am using is
this:
>
>
preg_match_all('/begincommand(.*)endcommand/',$messagebody,$commandOutta
ke
> ,P
> REG_PATTERN_ORDER);
> print $commandOuttake[0][0]." (0,0), ".$commandOuttake[0][1]."
(0,1)\n";
> print $commandOuttake[1][0]." (1,0), ".$commandOuttake[1][1]."
(1,1)\n";
>
> For this input
>
> random words begincommand another test string 1[endcommand] a couple
of
> random words [begincommand]2nd instance of command in same email test
> string
> [endcommand] and then a bunch of nonsense
>
> this code produces this output:
>
> begincommand another test string 1[endcommand] a\r\ncouple of random
words
> [begincommand]2nd instance of command in same email\r\ntest string
> [endcommand (0,0), (0,1) another test string 1[endcommand] a\r\ncouple
of
> random words [begincommand]2nd instance of command in same
email\r\ntest
> string [ (1,0), (1,1)
>
>
> In other words, the fact that I have the begincommand ... endcommand
> TWICE,
> the preg_match_all only accepts the OUTER open and close tags. It
never
> stops at the first endcommand as I am trying to make it do. The
string "
> a\r\ncouple of random words" should never show up!
>
> I've tried this with and without the PREG_PATTERN_ORDER, with ereg,
> preg_match and various and sundry other variations, and I am at a
loss.
> How
> do I change the criteria to stop at the first instance of a match?
How do
> I
> parse out only up to the first instance of "endcommand"?
>
>
> I am not certain if I am subscribed directly to this list, so in
> answering,
> would you be so kind as to cc: vania@pandorasdream.com?
>
> Thanks!
> _________________________
> Vania Smrkovski
> Internet Design and Programming
> vania@pandorasdream.com
> http://pandorasdream.com/
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php