Jump to content

[SOLVED] bbcode problems


xoligy

Recommended Posts

For some strange reason the bbcode i found on the internet isn't working right, (it use to, kinda!) i think it might be my main stylesheet overriding it im not sure tbh. but i have an image with me to help diagnose the problem oh and the code! Something ive also noticed if i use the quote or code command and have open quote above and below the comment i get space above the comment how would that be fixed? Also dont ask why "end" and "below" are on new lines i dont have a clue why!

 

Oh one more thing i just thought of would there be a way to use some parts of the bbcode on some pages but not others or would i require another bbcode pgae?

 

<style type="text/css">
<!--
body  {
   font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
}

.bold {
   font-weight: bold;
}

.italics {
   font-style: italic;
}

.underline {
   text-decoration: underline;
}

.strikethrough {
   text-decoration: line-through;
}

.overline {
   text-decoration: overline;
}

.sized {
   text-size:
}

.quotecodeheader {
   font-family: Verdana, arial, helvetica, sans-serif;
   font-size: 12px;
   font-weight: bold;
}

.codebody {
   background-color: #FFFFFF;
    font-family: Courier new, courier, mono;
    font-size: 12px;
    color: #006600;
    border: 1px solid #BFBFBF;
}

.quotebody {
   background-color: #FFFFFF;
    font-family: Courier new, courier, mono;
    font-size: 12px;
    color: #660002;
   border: 1px solid #BFBFBF;
}

.listbullet {
   list-style-type: disc;
   list-style-position: inside;
}

.listdecimal {
   list-style-type: decimal;
   list-style-position: inside;
}

.listlowerroman {
   list-style-type: lower-roman;
   list-style-position: inside;
}

.listupperroman {
   list-style-type: upper-roman;
   list-style-position: inside;
}

.listloweralpha {
   list-style-type: lower-alpha;
   list-style-position: inside;
}

.listupperalpha {
   list-style-type: upper-alpha;
   list-style-position: inside;
}
-->
</style>
<?php

function bbcode_format($str) {

	// Replace any html brackets with HTML Entities to prevent executing HTML or script
	// Don't use strip_tags here because it breaks [url] search by replacing & with amp
	$str = str_replace("<", "<", $str);
	$str = str_replace(">", ">", $str);

	// Convert new line chars to html <br /> tags
	$str = nl2br($str);

	// Set up the parameters for a URL search string
	$URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
	// Set up the parameters for a MAIL search string
	$MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@";

	// Perform URL Search
	$str = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '<a href="$1" target="_blank">$1</a>', $str);
	$str = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '<a href="$1" target="_blank">$2</a>', $str);

	// Perform MAIL Search
	$str = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '<a href="mailto:$1">$1</a>', $str);
	$str = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $str);

	// Check for bold text
	$str = preg_replace("(\[b\](.+?)\[\/b])is",'<span class="bold">$1</span>',$str);

	// Check for Italics text
	$str = preg_replace("(\[i\](.+?)\[\/i\])is",'<span class="italics">$1</span>',$str);

	// Check for Underline text
	$str = preg_replace("(\[u\](.+?)\[\/u\])is",'<span class="underline">$1</span>',$str);

	// Check for strike-through text
	$str = preg_replace("(\[s\](.+?)\[\/s\])is",'<span class="strikethrough">$1</span>',$str);

	// Check for over-line text
	$str = preg_replace("(\[o\](.+?)\[\/o\])is",'<span class="overline">$1</span>',$str);

	// Check for colored text
	$str = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","<span style=\"color: $1\">$2</span>",$str);

	// Check for sized text
	$str = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","<span style=\"font-size: $1px\">$2</span>",$str);

	// Check for list text
	$str = preg_replace("/\[list\](.+?)\[\/list\]/is", '<ul class="listbullet">$1</ul>' ,$str);
	$str = preg_replace("/\[list=1\](.+?)\[\/list\]/is", '<ul class="listdecimal">$1</ul>' ,$str);
	$str = preg_replace("/\[list=i\](.+?)\[\/list\]/s", '<ul class="listlowerroman">$1</ul>' ,$str);
	$str = preg_replace("/\[list=I\](.+?)\[\/list\]/s", '<ul class="listupperroman">$1</ul>' ,$str);
	$str = preg_replace("/\[list=a\](.+?)\[\/list\]/s", '<ul class="listloweralpha">$1</ul>' ,$str);
	$str = preg_replace("/\[list=A\](.+?)\[\/list\]/s", '<ul class="listupperalpha">$1</ul>' ,$str);
	$str = str_replace("[*]", "<li>", $str);

	// Check for font change text
	$str = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","<span style=\"font-family: $1;\">$2</span>",$str);

	// Declare the format for [code] layout
	$CodeLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
						<tr>
							<td class="quotecodeheader"> Code:</td>
						</tr>
						<tr>
							<td class="codebody">$1</td>
						</tr>
				   </table>';
	// Check for [code] text
	$str = preg_replace("/\[code\](.+?)\[\/code\]/is","$CodeLayout", $str);

	// Declare the format for [quote] layout
	$QuoteLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
						<tr>
							<td class="quotecodeheader"> Quote:</td>
						</tr>
						<tr>
							<td class="quotebody">$1</td>
						</tr>
				   </table>';

	// Check for [quote] text
	$str = preg_replace("/\[quote\](.+?)\[\/quote\]/is","$QuoteLayout", $str);

	// Images
	// [img=pathtoimage]
	$str = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1">', $str);

	// [img=widthxheight]image source[/img]
	$str = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<img src="$3" height="$2" width="$1">', $str);

	return $str;
}
?>

http://img76.imageshack.us/img76/1764/screenshotdo1.png

 

Dont worry about the "Â Â Â" thats just because ive opend the file in word as im in the libery! Oh to use the bbcode im placing it on the page that displays the news like this:

 

require_once('bbcode1.php');       

$str = $row['post'];

$str = bbcode_format($str);[/code][/code]

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.