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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.