Jump to content

BBCode help


naf

Recommended Posts

<?php
function forumbbcode($text) {
if(preg_match("/\[/", $text)) {
	$match = array(
		'/\[b\](.+?)\[\/b\]/is',
		'/\[u\](.+?)\[\/u\]/is',
		'/\[i\](.+?)\[\/i\]/is',
		'/\[url=(.+?)\](.+?)\[\/url\]/is',
		'/\[url\](.+?)\[\/url\]/is',
		'/\[quote\](.+?)\[\/quote\]/is'
	);

	$replace = array(
		'<b>$1</b>',
		'<u>$1</u>',
		'<i>$1</i>',
		'<a href="$1">$2</a>',
		'<a href="$1">$1</a>',
		'<div class="quote">$1</div>'
	);

	return preg_replace($match, $replace, $text);
}
}
?>

I have this kind of BBCode parser, but only problem is that it doesn't allow for ex. multiple quotes inside.

if i put

[quote]asd[quote]efg[/quote][/quote]

it will return

<div class="quote">asd[quote]efg[/quote]</div>

Link to comment
https://forums.phpfreaks.com/topic/204086-bbcode-help/
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.