phpSensei Posted August 29, 2007 Share Posted August 29, 2007 I am terrible at understanding, and writing regular expressions, and using preg_match(); . I need some code that can detect"<TAG> string </END TAG>", and replaces the <TAG> and </Tag> with something of my own... basically, this is for a ["b"][/"b"], and ["url"=""][/url] code I need for my forum.... Quote Link to comment Share on other sites More sharing options...
effigy Posted August 30, 2007 Share Posted August 30, 2007 Here's a quick example. You can find more by searching the forums for "bbcode". <pre> <?php $string = '<TAG>stuff</TAG>'; echo preg_replace('#<([^>]+)>(.*?)</\1>#', '[b]$2[/b]', $string); ?> </pre> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 30, 2007 Author Share Posted August 30, 2007 Here's a quick example. You can find more by searching the forums for "bbcode". <pre> <?php $string = '<TAG>stuff</TAG>'; echo preg_replace('#<([^>]+)>(.*?)</\1>#', '[b]$2[/b]', $string); ?> </pre> lol thanks, but i dont understand a word of it. @$#@$#@$#@%$#%$^%$$&%D>>>> Quote Link to comment Share on other sites More sharing options...
effigy Posted August 30, 2007 Share Posted August 30, 2007 Even after reading through the manual? Here's an explanation from Perl's YAPE::Regex::Explain: NODE EXPLANATION ---------------------------------------------------------------------- < '<' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- [^>]+ any character except: '>' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- > '>' ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- .*? any character except \n (0 or more times (matching the least amount possible)) ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- </ '</' ---------------------------------------------------------------------- \1 what was matched by capture \1 ---------------------------------------------------------------------- > '>' ---------------------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 30, 2007 Author Share Posted August 30, 2007 hey, thankyou... 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.