PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Jul 14, 2004 7:55 pm
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.php Code: 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
Last edited by
Dale on Wed Jul 14, 2004 9:55 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jul 14, 2004 7:57 pm
Code: Select all
<?php
$str = preg_replace('#\їb](.*?)\ї/b]#i','<b>\\1</b>',$str);
?>
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Jul 14, 2004 8:03 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jul 14, 2004 8:06 pm
well that was just an example for bold, you should be able to infer italics and underline..
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Wed Jul 14, 2004 8:13 pm
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);
}
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Wed Jul 14, 2004 8:38 pm
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);
}
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Jul 14, 2004 9:56 pm
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?
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Wed Jul 14, 2004 10:10 pm
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.
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Jul 14, 2004 10:22 pm
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.php Code: 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.php Code: 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.php Code: 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?
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Wed Jul 14, 2004 10:32 pm
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.
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Jul 14, 2004 10:40 pm
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'.
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Wed Jul 14, 2004 10:48 pm
Dale wrote: Code: Select all
if(isset($content)) {
$str = bbcode($content);
}
Should be....
Code: Select all
if(isset($content)) {
$content = bbcode($content);
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jul 14, 2004 10:51 pm
do you really want to insert the post-bbcoded content?
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Jul 14, 2004 10:52 pm
*Stares*
THANK YOU SO MUCH!!!!!!!1111111
*Yippee*