Goose Posted June 17, 2007 Share Posted June 17, 2007 I know there are resources on Google and here on this site for this topic, but I don't know what it is actually called so I don't know what to search for. So hopefully some of you smart people can help me out. I am doing a regular expressions search and I want to find a bbcode like tag. There is only one tag and its opening tag looks like [ail] and its closing tag looks like [/ail]. I want to replace the opening and closing tags and have been doing that easily with str_replace() but now I need to do more than replace text. I want to grab the text inside the tags with a regular expression. So, how do I match this pattern [ail]inside_text[/ail] and store the inside_text into a variable? Thanks! Quote Link to comment Share on other sites More sharing options...
Henaro Posted June 18, 2007 Share Posted June 18, 2007 You mean BBcode? Can I refer you to this post? http://www.phpfreaks.com/forums/index.php/topic,145449.0.html Quote Link to comment Share on other sites More sharing options...
Goose Posted June 18, 2007 Author Share Posted June 18, 2007 That does help ... but the thing that I would like to know how to do is take the regex result $1 and save it to php variable that I can use outside the regex. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 18, 2007 Share Posted June 18, 2007 If you don't want to replace anything, use preg_match_all(). The parenthetical expressions will be captured in an array. Quote Link to comment Share on other sites More sharing options...
Goose Posted June 18, 2007 Author Share Posted June 18, 2007 I am doing this now by using the preg_match function first and then replacing the matches later using preg_replace. Seems to work fine. Quote Link to comment Share on other sites More sharing options...
Goose Posted June 18, 2007 Author Share Posted June 18, 2007 I was writing my reply as you were submitting yours Wildbug, thanks for the tips though! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.