Flare Boards Posted October 27, 2007 Share Posted October 27, 2007 Ok guys I making a forum and want to add BBcode to it. How can i do this? I have looked everywhere? Quote Link to comment Share on other sites More sharing options...
derwert Posted October 27, 2007 Share Posted October 27, 2007 http://www.phpfreaks.com/forums/index.php/topic,149181.0.html http://www.phpfreaks.com/forums/index.php/topic,101566.0.html http://www.phpfreaks.com/forums/index.php/topic,105469.0.html http://www.phpfreaks.com/forums/index.php/topic,106448.0.html Quote Link to comment Share on other sites More sharing options...
Flare Boards Posted October 27, 2007 Author Share Posted October 27, 2007 Ok i have everything but i'm putting it into an php tag and the > keeps on closing it. Why is it doing this. Script: <META HTTP-EQUIV="Refresh" CONTENT="0; URL=main_forum.php"> <?php $host="**************"; // Host name $username="**************"; // Mysql username $password="**************"; // Mysql password $db_name="**************"; // Database name $tbl_name="**************"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'"; $result=mysql_query($sql)or die(mysql_error()); $rows=mysql_fetch_array($result); // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; } else { $Max_id = 1; } // get values that sent from form $a_name=$_POST['a_name']; $a_email=$_POST['a_email']; $a_answer=$_POST['a_answer']; $a_answer=strip_tags($a_answer); $a_answer=strip_tags($a_name); $a_answer=strip_tags($a_email); //BBCODE // convert [url=URL]link_title[/url] $pattern[] = '/\[url=(.*?)\](.*?)\[\/url\]/i'; $replace[] = '<a href="$1">$2</a>'; // convert [url]url_link[/url] $pattern[] = '/\[url\](.*?)\[\/url\]/i'; $replace[] = '<a href="$1">$1</a>'; // convert [img=image_link] $pattern[] = '/\[img\](.*?)\[\/img\]/i'; $replace[] = '<img src="$1">'; // convert [b]text[/b] $pattern[] = '/\[b\](.*?)\[\/b\]/i'; $replace[] = '<b>$1</b>'; // convert [code]CODE $pattern[] = '/\ [code\](.*?)\[\/code\]/i'; $replace[] = '<xmp>$1</xmp>'; $html = preg_replace($pattern, $replace, $a_answer); $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer $sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')"; $tbl_name2="forum_question"; // Switch to table "forum_question" // Insert last post $sqlmas="UPDATE $tbl_name2 SET lastpost=$datetime, lastpostname=$a_name"; $result2=mysql_query($sql2)or die(mysql_error()); if($result2){ // If added new answer, add value +1 in reply column $sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3)or die(mysql_error()); } else { echo "ERROR"; } mysql_close(); ?> [/code] Quote Link to comment Share on other sites More sharing options...
Flare Boards Posted October 27, 2007 Author Share Posted October 27, 2007 Ignroe the above posted scipt. It messed up. <META HTTP-EQUIV="Refresh" CONTENT="0; URL=main_forum.php"> <?php $host="**************"; // Host name $username="**************"; // Mysql username $password="**************"; // Mysql password $db_name="**************"; // Database name $tbl_name="**************"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'"; $result=mysql_query($sql)or die(mysql_error()); $rows=mysql_fetch_array($result); // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; } else { $Max_id = 1; } // get values that sent from form $a_name=$_POST['a_name']; $a_email=$_POST['a_email']; $a_answer=$_POST['a_answer']; $a_answer=strip_tags($a_answer); $a_answer=strip_tags($a_name); $a_answer=strip_tags($a_email); //BBCODE // convert link_title $pattern[] = '/\(.*?)\[\/url\]/i'; $replace[] = '<a href="$1">$2</a>'; // convert url_link $pattern[] = '/\[url\](.*?)\[\/url\]/i'; $replace[] = '<a href="$1">$1</a>'; // convert $pattern[] = '/\[img\](.*?)\[\/img\]/i'; $replace[] = '<img src="$1">'; // convert text $pattern[] = '/\[b\](.*?)\[\/b\]/i'; $replace[] = '<b>$1</b>'; // convert CODE $pattern[] = '/\[code\](.*?)\[\/code\]/i'; $replace[] = '<xmp>$1</xmp>'; $html = preg_replace($pattern, $replace, $a_answer); $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer $sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')"; $tbl_name2="forum_question"; // Switch to table "forum_question" // Insert last post $sqlmas="UPDATE $tbl_name2 SET lastpost=$datetime, lastpostname=$a_name"; $result2=mysql_query($sql2)or die(mysql_error()); if($result2){ // If added new answer, add value +1 in reply column $sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3)or die(mysql_error()); } else { echo "ERROR"; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
Flare Boards Posted October 27, 2007 Author Share Posted October 27, 2007 Does anyone know why the tag is closing? Quote Link to comment Share on other sites More sharing options...
derwert Posted October 27, 2007 Share Posted October 27, 2007 1) Post only relevant parts of your code; there is no reason to post parts that have nothing to do with the problem you're having. 2) Include one or two test scenarios that show the problem you're having. 3) Try to explain you're problem more clearly; a single sentence in most cases is not enough information. Quote Link to comment Share on other sites More sharing options...
Flare Boards Posted October 28, 2007 Author Share Posted October 28, 2007 Ok. What is happening is that the <?php section is getting closed by all of the > tags in the section. I cant figure out why this is happening. Is it just my FTP program that is doing this or is it the entire thing? Thats the best that i can do :/ Quote Link to comment Share on other sites More sharing options...
derwert Posted October 28, 2007 Share Posted October 28, 2007 I'm still not understanding what's happening. When you remove the meta tag and load the page what's happening? Quote Link to comment Share on other sites More sharing options...
Flare Boards Posted October 30, 2007 Author Share Posted October 30, 2007 All of the php works up to where a > sybol comes in. Then the rest of it appears as text. Quote Link to comment Share on other sites More sharing options...
Dragen Posted October 31, 2007 Share Posted October 31, 2007 do you mean the > tag here: $replace[] = '<a href="$1">$2'; Quote Link to comment Share on other sites More sharing options...
Flare Boards Posted November 3, 2007 Author Share Posted November 3, 2007 Yes, where ever that comes in, it stops the PHP. Quote Link to comment Share on other sites More sharing options...
Dragen Posted November 3, 2007 Share Posted November 3, 2007 try replacing it with: $replace[] = '<a href="' . $1 . '">' . $2; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.