Page 1 of 1

Selecting specific things from a variable.

Posted: Fri Feb 25, 2005 10:53 pm
by windwaker
So, let's say I have a variable, $var, and:

Code: Select all

$var = 'useless text and їtestyeah]';
I want to select the value between [ and ] and put it in another variable. Is there any way to do this?

Posted: Fri Feb 25, 2005 10:55 pm
by timvw
yes.

you could for example use strpos to determine the position of [ and ]. And then use substr to get the part between those positions..

or you could use preg_match to match things between [ and ] and then use the $matches...

Posted: Fri Feb 25, 2005 11:09 pm
by feyd
personally, I'd only use preg_match_all for it.. if you have multiple 'tags' you want to search for.. or unknown 'tags'.