Goldeneye Posted July 31, 2008 Share Posted July 31, 2008 I'm trying to create a no-parse tag that won't parse any BBCode placed inside these tags. [noparse][b]Foobar[/b][/noparse] would output (as a literal string): [b]Foobar[/b] The code is on the last lines of both arrays. So I tried: <?php function formatText($str) { $search = array( '/\[b\](.*?)\[\/b\]/si', '/\[i\](.*?)\[\/i\]/si', '/\[u\](.*?)\[\/u\]/si', '/\[noparse\](.*?)\[\/noparse\]/si' ); $replace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', str_replace('[','[','$1') . str_replace(']',']','$1') ); $str = preg_replace($search, $replace, $str); return $str; } ?> Those HTML enitity codes (seen on the last line of the $replace array) are just for the left ([) and right (]) square brackets. So what I thought this would do, is search for any square brackets, and replace them with their entity codes allowing them to remain unparsed. But instead, if I were to input: [noparse][ b ]old[ /b ][/noparse] (without the spaces); then oldold would be outputted. So, what is wrong here? A preemptive thanks to you. Quote Link to comment Share on other sites More sharing options...
ShaunO Posted July 31, 2008 Share Posted July 31, 2008 You need to make sure that it does the search and replace on the [noparse] tags first, add it to the top of the arrays. Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted July 31, 2008 Author Share Posted July 31, 2008 I already tried that actually, but it still gives me 'oldold'. So there has to be something that I'm missing. Quote Link to comment Share on other sites More sharing options...
ShaunO Posted July 31, 2008 Share Posted July 31, 2008 You may need to do the [noparse] replace prior to the rest of the replacements and independant of them. It could just be an oddity of using arrays and preg replace. Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted July 31, 2008 Author Share Posted July 31, 2008 Yeah, I just tried that and guess what? I got the same result as before. It could be an oddity, but it could also be that I've missed something in the process. Either way, this seemingly simple task is defeating me. Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted July 31, 2008 Author Share Posted July 31, 2008 <bump> Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted August 2, 2008 Author Share Posted August 2, 2008 <bump> 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.