> say i have a line of text like: [blah], [rah] PH33r Us! [moo]
> 
> how can I extract all the text in the brackets and set it as a var, im
> totally stuck, my idea was to use strstr() but that wouldnt work as
all
> the
> tags were not at the end :(

Assuming you want to replace [foo] with the value in $foo, you can use
something like this:

$str = "this [foo] is a [test] okay?";

$foo = "crap_foo";
$test = "crap_test";

$nstr = preg_replace("/\[([a-z]+)\]/ie",'\$$1',$str);

echo $str . "<br>---<br>" . $nstr;

No error checking, so if $foo doesn't exist, you'll get a warning and
empty string inserted.

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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

Reply via email to