Home › Forums › Archives › Computer Support › Computer Support Discussion › Help Creating A Type of BBcode.
- This topic has 2 replies, 2 voices, and was last updated 18 years, 11 months ago by
Spike.
-
AuthorPosts
-
March 12, 2007 at 5:15 am #26486
seb_thib_55
MemberI created a BBcode type of script for my forum.
Sebby’s Arcade
It works in the main post but then for replies I get this:[PHP]Fatal error: Cannot redeclare bbcode_format() (previously declared in /home/sebbyarc/public_html/sebbycode.php:8) in /home/sebbyarc/public_html/sebbycode.php on line 8[/PHP]The reason for this is because I repeat this code twice:
[PHP]$str = $maindata[post];
$str2 = $maindata[post];
require(“sebbycode.php”);
$topicpost=$str;
[/PHP]
sebbycode.php contains all the bbcode. How can I fix this?SEBBYCODE.PHP
[PHP]$str=nl2br($str2);
$str = htmlentities($str);
$str = htmlentities($str2);
$str=nl2br($str);
function bbcode_format ($str) {// replace the codes
$str = preg_replace (‘/(.*?)/is’, ‘$1‘, $str);
$str = preg_replace (‘/(.*?)/is’, ‘$1‘, $str);
$str = preg_replace (‘/(.*?)/is’, ‘$1‘, $str);
$str = preg_replace (‘/(.*?)/is’,’$2‘, $str);
$str = preg_replace (‘/[fontsize=(.*?)](.*?)[/fontsize]/is’,’$2‘, $str);
$str = preg_replace (‘/[fontcolor=(.*?)](.*?)[/fontcolor]/is’,’$2‘, $str);
$str = preg_replace (‘/[fontface=(.*?)](.*?)[/fontface]/is’,’$2‘, $str);
$str = preg_replace (‘/[highlight=(.*?)](.*?)[/highlight]/is’,’$2‘, $str);
$str = preg_replace (‘/(.*?)/is’,’$1‘, $str);
$str = preg_replace (‘//is’,’
‘, $str);
$str = preg_replace (‘/[mail](.*?)[/mail]/is’,’$1‘, $str);
$str = preg_replace (‘/[align=(left|center|right)](.*?)[/align]/is’,’$2‘, $str);
$str = preg_replace (‘/
/is’,’
‘, $str);
$str = preg_replace (‘/(.*?)
/is’,’Quote:
$1‘, $str);
$str = preg_replace (‘/[code](.*?)[/code]/is’,’Code:$1‘, $str);
return $str;
}$str = bbcode_format($str);
$i=-1;
while ($i <= $csmile) {
$i++;
$str = str_replace(rtrim($smilies[$i]), ““,$str);
}
for($gx=-1;$gx<$tb;$gx++) {
if($badwords[$gx] != “”) {
$str= eregi_replace(rtrim($badwords[$gx]), “@!&^*%”, $str);
}
}[/PHP]THREAD.PHP
this is used for the main post. It takes $maindata[post] and converts it and stuff:
LINE: 170 roughly
[PHP]$str = $maindata[post];
$str2 = $maindata[post];
require(“sebbycode.php”);
$topicpost=$str;
[/PHP]Then for the replies I retake the code above but get the error posted.
LINE 290 roughlyFor the entire thread.php visit:
http://www.sebbyarcade.com/boards/thread.phps
OR
I grabbed roughly what you may need:
[PHP]
$maindata = @mysql_fetch_array(run_query(“SELECT * FROM topics WHERE board_id='”.$_GET.”‘ AND id='”.$_GET.”‘”));
$str = $maindata[post];
$str2 = $maindata[post];
require(“sebbycode.php”);
$topicpost=$str;$dateposted=date(“F jS Y – h:i A”, $maindata[date]);
$dateedited=date(“F jS Y – h:i A”, $maindata[editdate]);
$postcount = @mysql_fetch_array(mysql_query(“SELECT * FROM user_info WHERE user=’$profiledata2[name]'”));require(“boards/boardslinksection.php”);
echo ” | Post Reply | New Topic“;echo”
SebbyBoards > $boarddata[name] > $maindata[title] “;if($maindata[locked]==”Yes”){echo”
“;}
echo”“;
if($staff[group]==”Admin” || $staff[group]==”Moderator”){
echo”“;
}echo”
Author Message “;
echo “
$profiledata2[name]$profiledata2[group]
“;if($profiledata2[avatar]==””){
echo”
“;
}else{
echo”“;
}
if($staff[group]==”Admin” || $staff[group]==”Moderator”){
echo”
IP: $maindata[ip]“;
}
echo”
Posts: $postcount[postcount]
“;
if ($profiledata2[gender]){
echo”
“;
}
echo”
($trophycount)$dateposted EDIT | DELETE | QUOTE “;
echo”$topicpost”;
if($postcount[signature]){
$realsignature=nl2br($postcount[signature]);
echo”
$realsignature”;
}
echo”“;
if($maindata[editdate]){
echo”Post last edited by $maindata[edituser] on $dateedited “;
}
echo”“;
$threadsdata = mysql_query(“SELECT * FROM threads where board_id='”.$_GET[bid].”‘ AND thread_id='”.$_GET[tid].”‘”);
echo “March 12, 2007 at 1:33 pm #158745Spike
MemberThat’s not how you use functions at all. You should not just define a variable and then expect a function to parse that variable.
Do it like this:
[php]
require_once(“sebbycode.php”);
$str = bbcode_format($maindata[post]);
$str2 = bbcode_format($maindata[post]);
$topicpost=$str;[/php]
Take these lines out at the top of sebbycode.php:[php]$str=nl2br($str2);
$str = htmlentities($str);
$str = htmlentities($str2);
$str=nl2br($str);[/php]
And put these lines at the TOP of your function:[php]$str = htmlentities($str);
$str=nl2br($str);[/php]March 12, 2007 at 4:47 pm #158744seb_thib_55
MemberEverything works. 😀
Thank you very much! 😀 -
AuthorPosts
- You must be logged in to reply to this topic.