cheesycarrion Posted December 19, 2008 Share Posted December 19, 2008 I'm trying to make it so that any html or bbcode inside the [ code ] tag isn't parsed. here's what I've got: (it doesn't work. stuff inside the [ code ] tag still gets treated like normal.) <?php function parse_bbcode($input) { $bb_replace = array( '/\[img\](.*?)\[\/img\]/is', '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[url_blank\=(.*?)\](.*?)\[\/url_blank\]/is', '/\[textarea\](.*?)\[\/textarea\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[url_blank\](.*?)\[\/url_blank\]/is', '/\[quote\=(.*?)\](.*?)\[\/quote\]/is', '/\[quote\](.*?)\[\/quote\]/is', '/\[code\](.*?)\[\/code\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', '/\[size\=(.*?)\](.*?)\[\/size\]/is' ); $bb_replacements = array( '<img src="$1" alt="$1" />', '<span style="font-weight: bold;">$1</span>', '<span style="font-style: italic;">$1</span>', '<span style="text-decoration: underline;">$1</span>', '<a href="$1">$2</a>', '<a href="$1" target="_blank">$2</a>', '<textarea>$1</textarea>', '<a href="$1">$1</a>', '<a href="$1" target="_blank">$1</a>', '<span class="quote">$1 said:<span>$2</span></span>', '<span class="quote">quote:<span>$1</span></span>', '<code>' . str_replace(array("[","]"),array("[","]"),htmlspecialchars('$1')) . '</code>', '<span style="color:$1;">$2</span>', '<span style="font-size:$1;">$2</span>' ); return preg_replace($bb_replace,$bb_replacements,$input); } ?> Link to comment https://forums.phpfreaks.com/topic/137752-bbcode-code-tag/ Share on other sites More sharing options...
aseaofflames Posted December 20, 2008 Share Posted December 20, 2008 try this: <?php function parse_bbcode($input) { preg_match_all('/\[code\](.*?)\[\/code\]/is',$input, $code) foreach($code[0] as $cur) { $input = str_replace($cur[0],htmlspecialchars($cur[0]),$input); } $bb_replace = array( '/\[img\](.*?)\[\/img\]/is', '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[url_blank\=(.*?)\](.*?)\[\/url_blank\]/is', '/\[textarea\](.*?)\[\/textarea\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[url_blank\](.*?)\[\/url_blank\]/is', '/\[quote\=(.*?)\](.*?)\[\/quote\]/is', '/\[quote\](.*?)\[\/quote\]/is', '/\[code\](.*?)\[\/code\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', '/\[size\=(.*?)\](.*?)\[\/size\]/is' ); $bb_replacements = array( '<img src="$1" alt="$1" />', '<span style="font-weight: bold;">$1</span>', '<span style="font-style: italic;">$1</span>', '<span style="text-decoration: underline;">$1</span>', '<a href="$1">$2</a>', '<a href="$1" target="_blank">$2</a>', '<textarea>$1</textarea>', '<a href="$1">$1</a>', '<a href="$1" target="_blank">$1</a>', '<span class="quote">$1 said:<span>$2</span></span>', '<span class="quote">quote:<span>$1</span></span>', '<code>$1</code>', '<span style="color:$1;">$2</span>', '<span style="font-size:$1;">$2</span>' ); return preg_replace($bb_replace,$bb_replacements,$input); } ?> Link to comment https://forums.phpfreaks.com/topic/137752-bbcode-code-tag/#findComment-720184 Share on other sites More sharing options...
cheesycarrion Posted December 23, 2008 Author Share Posted December 23, 2008 I tried using your variation but unfortunately it still doesn't work and parses the content inside code tags regularly. Link to comment https://forums.phpfreaks.com/topic/137752-bbcode-code-tag/#findComment-722751 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.