Hello!
I'm making a site where users can post news, and I'm trying to implement bbcode to make it simple for all the users, I'm not very experienced with php, so I hope someone can help me.
firstly I have have the form script.
<?php include("header.php"); ?>
<br><h3>New news article</h3>
<div id="addnews">
<br><br>
<form method="post" action="/lodge/addnewsprocess.php">
Title:<br><input type="Text" name="title" cols=30><br>
Content:<br><textarea name="content" rows=30 cols=55></textarea>
<br><input type="submit" value="Submit" name="register">
</form>
</div>
<?php include("footer.php"); ?>
Then the processing to the database
<?php
ob_start();
session_start();
?>
<?php include("header.php"); ?>
<?php
//variables from the form
$title = $_POST['title'];
$content = $_POST['content'];
$date = date("F j Y");
$user = $_SESSION['username'];
//check that user have filled in everything
$errors = 0;
$emessage = "<center>Sorry, we enounctered the following errors when processing your article:<br /><ul>";
if(empty($title) || empty($content))
{
$errors = 1;
$emessage .= "<li>Sorry, you must fill in <strong>all</strong> fields. Please go back and try again.</li>";
}
//if the user made errors, show messages
if($errors != 0)
{
$emessage .= "</font></center>";
die("$emessage");
}
//perform query, inseting user submitted data
mysql_query("INSERT INTO news (title, content, date, user) VALUES ('$title', '$content', '$date', '$user')") or die(mysql_error());
//message if everything went well.
echo("<center><br><br><br>Thanks for posting. Click <a href=\"/lodge/mainpage.php\">here</a> to return to the member's page.</font></center>");
ob_end_flush();
?>
<?php include("footer.php"); ?>
I have downloaded a bbcode script from http://www.bbcode.org/implementations.php
<?php
/*
* phpBBCode
*
* @website www.swaziboy.com
* @author Duncan Mundell
* @updated 03/2003
* @version 1.0a
*/
function BBCode($Text) {
// 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
$content = str_replace("<", "<", $content);
$content = str_replace(">", ">", $content);
// Convert new line chars to html <br /> tags
$content = nl2br($content);
// 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
$content = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '<a href="$1" target="_blank">$1</a>', $content);
$content = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '<a href="$1" target="_blank">$2</a>', $content);
// Perform MAIL Search
$content = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '<a href="mailto:$1">$1</a>', $content);
$content = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $content);
// Check for bold text
$content = preg_replace("(\[b\](.+?)\[\/b])is",'<span class="bold">$1</span>',$content);
// Check for Italics text
$content = preg_replace("(\[i\](.+?)\[\/i\])is",'<span class="italics">$1</span>',$content);
// Check for Underline text
$content = preg_replace("(\[u\](.+?)\[\/u\])is",'<span class="underline">$1</span>',$content);
// Check for strike-through text
$content = preg_replace("(\[s\](.+?)\[\/s\])is",'<span class="strikethrough">$1</span>',$content);
// Check for over-line text
$content = preg_replace("(\[o\](.+?)\[\/o\])is",'<span class="overline">$1</span>',$content);
// Check for colored text
$content = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","<span style=\"color: $1\">$2</span>",$content);
// Check for sized text
$content = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","<span style=\"font-size: $1px\">$2</span>",$content);
// Check for list text
$content = preg_replace("/\[list\](.+?)\[\/list\]/is", '<ul class="listbullet">$1</ul>' ,$content);
$content = preg_replace("/\[list=1\](.+?)\[\/list\]/is", '<ul class="listdecimal">$1</ul>' ,$content);
$content = preg_replace("/\[list=i\](.+?)\[\/list\]/s", '<ul class="listlowerroman">$1</ul>' ,$content);
$content = preg_replace("/\[list=I\](.+?)\[\/list\]/s", '<ul class="listupperroman">$1</ul>' ,$content);
$content = preg_replace("/\[list=a\](.+?)\[\/list\]/s", '<ul class="listloweralpha">$1</ul>' ,$content);
$content = preg_replace("/\[list=A\](.+?)\[\/list\]/s", '<ul class="listupperalpha">$1</ul>' ,$content);
$content = str_replace("[*]", "<li>", $Text);
// Check for font change text
$content = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","<span style=\"font-family: $1;\">$2</span>",$content);
// 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
$content = preg_replace("/\[code\](.+?)\[\/code\]/is","$CodeLayout", $content);
// 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 [code] text
$content = preg_replace("/\[quote\](.+?)\[\/quote\]/is","$QuoteLayout", $content);
// Images
// [img]pathtoimage[/img]
$content = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1">', $content);
// [img=widthxheight]image source[/img]
$content = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<img src="$3" height="$2" width="$1">', $content);
return $Text;
}
?>
How can I modify my scripts to make this work? I've try'd some things, but nothing seem to work.