PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
windwaker
Forum Newbie
Posts: 21 Joined: Sun Feb 13, 2005 11:18 am
Post
by windwaker » Fri Feb 25, 2005 10:53 pm
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?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Fri Feb 25, 2005 10:55 pm
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...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 25, 2005 11:09 pm
personally, I'd only use preg_match_all for it.. if you have multiple 'tags' you want to search for.. or unknown 'tags'.