Re: scan a text string to pick up certain words
| From: | Justin Patrin | Date: | Wed, 11 Aug 2004 22:16:38 +0000 |
| Subject: | Re: scan a text string to pick up certain words | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-193514@lists.php.net to get a copy of this message | ||
On Wed, 11 Aug 2004 18:07:57 -0400, Alex Shi <chpshi@stonix.com> wrote:
> Hi All,
>
> I guess regex can do the trick but I don't know much about regex :((
> Here is what I want:
> Say a text string in which there're several words enclosed by "{"
> and "}", for example {hellow}. I need to pick up each of the words
> like this and print them or do some processing one by one.
> Can any one please show me an example how to do this in PHP.
> Thanks in advance!
>
preg_match_all('/{([^}]*)}/', $text, $matches);
print_r($matches[1]);
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--