Page 1 of 1
BBCode Problems...
Posted: Wed Jul 14, 2004 7:55 pm
by Dale
I've added a BBCode file in an includes folder and added a message to the database via a form... but on the page where it says 'Your New Thread Has Been Posted' I get these errors:
Warning: Unknown modifier 'b' in /home2/dframe/public_html/projects/1/inc/bbcode.php on line 5
Warning: Unknown modifier ']' in /home2/dframe/public_html/projects/1/inc/bbcode.php on line 8
Warning: Unknown modifier ']' in /home2/dframe/public_html/projects/1/inc/bbcode.php on line 11
bbcode.phpCode: Select all
<?php
function bbcode($str)
{
// Bold Text (їb]text goes hereї/b])
$str = preg_replace('/(їb])(.+?)(ї/b])/i', "<b>\2</b>",$str);
// Italic Text (їi]text goes hereї/i])
$str = preg_replace('/(їi])(.+?)(ї/i])/i', "<i>\2</i>",$str);
// Underlined Text (їu]text goes hereї/u])
$str = preg_replace('/(їu])(.+?)(ї/u])/i', "<u>\2</u>", $str);
return $str;
}
?>
Please Help Me

Posted: Wed Jul 14, 2004 7:57 pm
by feyd
Code: Select all
<?php
$str = preg_replace('#\їb](.*?)\ї/b]#i','<b>\\1</b>',$str);
?>
Posted: Wed Jul 14, 2004 8:03 pm
by Dale
Thanks for a fast reply... I still get this though:
Warning: Unknown modifier ']' in /home2/dframe/public_html/projects/1/inc/bbcode.php on line 8
Warning: Unknown modifier ']' in /home2/dframe/public_html/projects/1/inc/bbcode.php on line 11
Posted: Wed Jul 14, 2004 8:06 pm
by feyd
well that was just an example for bold, you should be able to infer italics and underline..
Posted: Wed Jul 14, 2004 8:13 pm
by redmonkey
You could do the lot in one hit...
Code: Select all
function bbcode($str)
{
return preg_replace('/\[(b|i|u)](.+?)\[\/\\1]/i', '<$1>$2</$1>', $str);
}
Posted: Wed Jul 14, 2004 8:38 pm
by redmonkey
Actually, scratch that, it won't cater for nested tags perhaps....
Code: Select all
function bbcode($str)
{
$search = array('/\[b](.+?)\[\/b]/i', '/\[i](.+?)\[\/i]/i', '/\[u](.+?)\[\/u]/i');
$replace = array('<b>$1</b>', '<i>$1</i>', '<u>$1</u>');
return preg_replace($search, $replace, $str);
}
Posted: Wed Jul 14, 2004 9:56 pm
by Dale
I get no error but now i still can see
Code: Select all
їb]Boldї/b] - їi]Italicsї/i] - їu]Underlinedї/u]
.
Question: At the top of which file do i add the following line:
Code: Select all
if(isset($content)) {
$str = bbcode($content);
}
newthreaded.php - The page that tells me the thread has been posted and contains all the mysql queries for inserting it into the database.
... or ...
viewthread.php - The page where i view the thread?
Posted: Wed Jul 14, 2004 10:10 pm
by redmonkey
Dale wrote:Question: At the top of which file do i add the following line:
Code: Select all
if(isset($content)) {
$str = bbcode($content);
}
newthreaded.php - The page that tells me the thread has been posted and contains all the mysql queries for inserting it into the database.
... or ...
viewthread.php - The page where i view the thread?
That depends, at what stage is the processing on the text done? on the way into the database? or on the way out?
The fact that you are still seeing the bbcode tags suggests that you are either not calling the function correctly (or at all), you are not calling the function at the correct time within the script or you are not assigning the results of the function to the correct variable.
Posted: Wed Jul 14, 2004 10:22 pm
by Dale
hmmm... not the right time for a problem like this eh? Its 4:16am here im knackered and this problem is keeping me awake...
Heres the pages:
newthread.phpCode: Select all
<?php
include("header.php");
?>
<table bgcolor="#555576" border="0" cellspacing="1" cellpadding="5" width="95%">
<tr>
<td bgcolor="#51485f" width="100%" align="left" colspan="2"><font face="verdana" size="2" color="#FFFFFF"><b>Post A New Thread</b></font></td></tr>
<tr valign="top">
<td bgcolor="#C9C9C9" width="20%" align="left">
<center>
<table bgcolor="#555576" border="0" cellspacing="1" cellpadding="5" width="95%">
<tr>
<td bgcolor="#51485F"><center><font face="verdana" size="2" color="#FFFFFF"><b>Logged In</b></font></center></td>
</tr>
<tr>
<td bgcolor="#C9C9C9" width="100%" align="left"><font face="verdana" size="2"><b>Dale</b> [<a href=".">Log Out</a>]</font></td>
</tr>
</table>
<br>
<table bgcolor="#555576" border="0" cellspacing="1" cellpadding="5" width="95%">
<tr>
<td bgcolor="#51485F" colspan="2"><center><font face="verdana" size="2" color="#FFFFFF"><b>Smilies</b></font></center></td>
</tr>
<?
$result = mysql_query("SELECT * FROM df_smilies") or die(mysql_error());
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$code=$r["code"];
echo "<tr>
<td bgcolor="#C9C9C9" width="20%" align="left"><img src="./images/smilies/$id.gif"></td>
<td bgcolor="#C9C9C9" width="80%" align="left"><font face="verdana" size="2">$code</font></td>
</tr>";
}
?>
</table>
</center>
</td>
<td bgcolor="#C9C9C9" width="80%" align="left">
<font face="verdana" size="2">
<form method="post" action="newthreaded.php">
<input type="hidden" name="fid" value="<?php echo("$fid"); ?>">
Author:<br><input type="text" name="author"><br>Title:<br><input type="text" name="title"><br>Message:<br><textarea name="content" rows="20" cols="50"></textarea></font>
<br>
<input type="submit" value="Post New Thread">
</form>
</td>
</tr>
<?
include("footer.php");
?>
newthreaded.phpCode: Select all
<?php
include("header.php");
if(isset($content)) {
$str = bbcode($content);
}
?>
<table bgcolor="#555576" border="0" cellspacing="1" cellpadding="5" width="95%">
<tr>
<td bgcolor="#51485f" width="100%" align="left" colspan="2"><font face="verdana" size="2" color="#FFFFFF"><b><center>New Thread Posted!</center></b></font></td></tr>
<tr valign="top">
<td bgcolor="#C9C9C9" width="20%" align="left"><font face="verdana" size="2"><center><?php
$result = mysql_query("UPDATE df_forums SET threads=threads+1 WHERE id='$fid'");
$result = mysql_query("UPDATE df_forums SET posts=posts+1 WHERE id='$fid'");
$result = mysql_query ("INSERT INTO df_threads (id, title, content, author, icon, posted, fid, replies, views) VALUES ('$id', '$title', '$content', '$author', '$icon', '$posted', '$fid', '0', '0')");
if($result)
{
print "Your New Thread has been posted!";
}
?></center></td>
</tr>
<?
include("footer.php");
?>
inc/bbcode.phpCode: Select all
<?php
function bbcode($str)
{
$search = array('/\[b](.+?)\[\/b]/i', '/\[i](.+?)\[\/i]/i', '/\[u](.+?)\[\/u]/i');
$replace = array('<b>$1</b>', '<i>$1</i>', '<u>$1</u>');
return preg_replace($search, $replace, $str);
}
?>
Hope that helps?
Posted: Wed Jul 14, 2004 10:32 pm
by redmonkey
Well, from what I can gather you have the 'if(isset.....' in the correct file however, I don't see the inc/bbcode.php file being included anywhere.
I'm not even going to begin on the various potential problems your code has.
Posted: Wed Jul 14, 2004 10:40 pm
by Dale
I know my code is a mess... the 'inc/bbcode.php' file is included in the 'global.php' file which is included in the 'header.php' which is included at the top of the 'newthreaded.php'.
Posted: Wed Jul 14, 2004 10:48 pm
by redmonkey
Dale wrote:Code: Select all
if(isset($content)) {
$str = bbcode($content);
}
Should be....
Code: Select all
if(isset($content)) {
$content = bbcode($content);
}
Posted: Wed Jul 14, 2004 10:51 pm
by feyd
do you really want to insert the post-bbcoded content?
Posted: Wed Jul 14, 2004 10:52 pm
by Dale

*Stares*
THANK YOU SO MUCH!!!!!!!1111111
*Yippee*