Jump to content

bbcode (code tag) is not parsing multiple lines


terungwa

Recommended Posts

The bbcode below is not parsing code on multiple lines or recognizing line breaks, except the full content code is on one line.

<?php
function bbcode2html($var)
	{
		// code synthax highlighter
		$var = preg_replace('/\[code](.+?)\[\/code]/i',
		'<pre><code>$1</code></pre>', $var);
		return $var;
	}
$content= '[code] <!DOCTYPE
	html> [/code]';
echo $content= bbcode2html($content);
?>

I attempted introducing a new line recognition character into the regex as shown below, but its not working.

<?php
function bbcode2html($var)
	{
		// code synthax highlighter
		$var = preg_replace('/\[code]\r\n(.+?)\[\/code]/i',
		'<pre><code>$1</code></pre>', $var);
		return $var;
	}
$content= '[code] <!DOCTYPE
	html> [/code]';
echo $content= bbcode2html($content);
?>


I would appreciate your suggestions.

 

Thanks.

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.