[PHP] scan a text string to pick up certain words

2004-08-11 Thread Alex Shi
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!

Alex

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] scan a text string to pick up certain words

2004-08-11 Thread Justin Patrin
On Wed, 11 Aug 2004 18:07:57 -0400, Alex Shi [EMAIL PROTECTED] 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--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] scan a text string to pick up certain words

2004-08-11 Thread Alex Shi
It works the way as supposed :)
Thanks!

 On Wed, 11 Aug 2004 18:07:57 -0400, Alex Shi [EMAIL PROTECTED] 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--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php