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.... Link to comment https://forums.phpfreaks.com/topic/67252-php-regex-question/ 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> Link to comment https://forums.phpfreaks.com/topic/67252-php-regex-question/#findComment-337704 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>>>> Link to comment https://forums.phpfreaks.com/topic/67252-php-regex-question/#findComment-337794 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 ---------------------------------------------------------------------- > '>' ---------------------------------------------------------------------- Link to comment https://forums.phpfreaks.com/topic/67252-php-regex-question/#findComment-337817 Share on other sites More sharing options...
phpSensei Posted August 30, 2007 Author Share Posted August 30, 2007 hey, thankyou... Link to comment https://forums.phpfreaks.com/topic/67252-php-regex-question/#findComment-337828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.