burhankhan Posted July 8, 2007 Share Posted July 8, 2007 Hi: I have written a class to parse bbcode. I am having little problem with regular expression. preg_replace('/\[quote\](.+?)\[\/quote\]/is', '<pre>$1</pre>', $mytext) This is simple code to convert all QUOTES tags. It is working fine. But when i have text like this: [ quote ]here is some text[ quote ]here is more text[ / quote ][ / quote ] Then it is creating problem. It will print this: [ quote ]here is some text [ / quote ] Is there any solution to parse 2 or more level QUOTES?? Thanks Burhan Khan Quote Link to comment https://forums.phpfreaks.com/topic/58963-code-parse-help/ Share on other sites More sharing options...
wildteen88 Posted July 8, 2007 Share Posted July 8, 2007 You'll want to use preg_match within a while loop and then with each match found you'll then use preg_replace. I'll back with some code in abit. Quote Link to comment https://forums.phpfreaks.com/topic/58963-code-parse-help/#findComment-292604 Share on other sites More sharing options...
sasa Posted July 8, 2007 Share Posted July 8, 2007 maybe call preg_replace more then one time <?php $mytext = '[quote]here is some text[quote]here is some text[/quote][/quote]'; while (preg_match('/\[quote\](.+?)\[\/quote\]/is', $mytext)) $mytext = preg_replace('/\[quote\](.+?)\[\/quote\]/is', '<pre>$1</pre>', $mytext); echo $mytext; ?> Quote Link to comment https://forums.phpfreaks.com/topic/58963-code-parse-help/#findComment-292612 Share on other sites More sharing options...
burhankhan Posted July 8, 2007 Author Share Posted July 8, 2007 It is working for me! Thanks for you help SASA. Quote Link to comment https://forums.phpfreaks.com/topic/58963-code-parse-help/#findComment-292679 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.