Re: preg_split() Help
| From: | Andrei Zmievski | Date: | Tue, 23 May 2000 16:52:02 +0000 |
| Subject: | Re: preg_split() Help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-375@lists.php.net to get a copy of this message | ||
> I'll have an input line like this --
>
> <$World> blah <$ Wide> blah <$ Web >
>
> I need a regular expression to parse this and give me an array
> of ("World", "Wide", "Web"). What's throwing me for a loop
> at
> the moment is the optional spaces before/after the <$ and >
> delimiters. These spaces may or may not be there for any of
> the 'fields'. For that matter there could be from 1 to n
> 'fields' in the input.
You need preg_match_all(), rather than split:
preg_match_all("/<\\\$\s*(\w+)\s*>/U", $text, $matches);
Then your matches can be found in $matches[1].
-Andrei
Computer, if you don't open that exit hatch this moment I shall zap straight
off to your major data banks and reprogram you with a very large axe.
-- Douglas Adams / The Hitchhiker's Guide to the Galaxy