Jump to content

noparse BBCode


Goldeneye

Recommended Posts

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('[','&#91;','$1') . str_replace(']','&#93;','$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 (&#91;) and right (&#93;) 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.

Link to comment
https://forums.phpfreaks.com/topic/117445-noparse-bbcode/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.