Rosst Posted June 18, 2006 Share Posted June 18, 2006 I made a bbcode function for my news system, I wanted to add a php tag and so I tried but it didn't work, here is my code:[code]<?function bbcode($content){$content = nl2br(htmlspecialchars($content)); $bbcode = array( "'\[b\](.*?)\[/b\]'", "'\[i\](.*?)\[/i\]'", "'\[u\](.*?)\[/u\]'", "'\[code\](.+?)\[/code\]'", "'\[url=(.*?)\](.*?)\[/url\]'", "'\[url\](.*?)\[/url\]'", "'\[img\](.*?)\[/img\]'", "'\[php\](.*?)\[/php\]'" ); $html = array( "<b>\\1</b>", "<i>\\1</i>", "<u>\\1</u>", "<strong>Code:</strong><div style=\"margin:0px 10px;padding:5px;border:1px dotted #FFFFFF;width:80%;\"></em>\\1</em></div>", "<a href=\"\\1\" target=\"_BLANK\">\\2</a>", "<a href=\"\\1\" target=\"_BLANK\">\\1</a>", "<img border=\"0\" src=\"\\1\">", "<strong>PHP:</strong><div style=\"margin:0px 10px;padding:5px;border:1px dotted #FFFFFF;width:80%;\"></em><?php highlight_sting(\"\\1\"); ?></em></div> ); $content = preg_replace($bbcode, $html, $content); return nl2br($content);}?>[/code]Oh also my news comments aren't showing up (I get the header and menu but no content) here is my code:[code]<?phpob_start(); // allows us to use cookiesinclude("config.php"); // includes the config fileif ($logged['username']){ // if the user is logged in they can view thisswitch($_GET['view']){ // news_comments.php?view=case 'news': // news_comments.php?view=news&id=$id$id = $_GET['acl']; // grabs the requested id$select = "select * from news where id=$id"; // selects the requested id from the database$select2 = "select * from news_comments where nid=$id ORDER BY id DESC"; // grabs comments for the news article$getnews = mysql_query($select) // querys the news dbor die(mysql_error()); // die error!$getcomments = mysql_query($select2); // querys the comments dbif (mysql_num_rows($getnews) == "0") { // if we are returned a nulled resultecho 'Unable to find the article in our database'; // nothing found error!exit(); // exit}$row = mysql_fetch_array($getnews) // arrayor die(mysql_error()); // error!$nid = $row['id']; // news id$ntitle = $row['title']; // news title$ncontent = bbcode($row['content']); // news content with bbcode wrapped around it$nauthor = $row['author']; // news author$postdate = $row['postdate']; // news date echo ("<tr> <td>$ntitle Posted by <a href=\"index.php?id=memb&user=$nauthor\">$nauthor</a> At $postdate<br></td> </tr> <tr> <td>$ncontent<br><br>Comments:<br></td> </tr>"); if (mysql_num_rows($getcomments) == "0") { // if we are returned a nulled result for the comments echo a link to add emecho("There are no comments!<br>[<a href=\"index.php?id=newscom&view=addcomment&acl=$id\">Add a comment</a>]"); // add a link!}if($logged[username] && $logged[level] ==5) // if the user is a adminwhile($rowc= mysql_fetch_array($getcomments)){ // fetches an array$cauthor = $rowc['author']; // comment author$ccomment = bbcode($rowc['content']); // comment content$cdate = $rowc['postdate']; // comment date echo ("<tr> <td>Comment Posted by <a href=\"index.php?id=memb&user=$nauthor\">$cauthor</a> At $cdate [<a href=\"index.php?id=newad&view=editcomment&acl=$id\">Edit</a>] [<a href=\"index.php?id=newad&view=deletecomment&acl=$id\">Delete</a>]<br></td> </tr> <tr> <td>$ccomment<br><br></td> </tr>"); }while($rowc= mysql_fetch_array($getcomments)){ // if the user is a normal user echo this$cauthor = $rowc['author']; // comment author$ccomment = bbcode($rowc['content']); // comment content$cdate = $rowc['postdate']; // comment date echo ("<tr> <td>Comment Posted by <a href=\"index.php?id=memb&user=$nauthor\">$cauthor</a> At $cdate<br></td> </tr> <tr> <td>$ccomment<br><br></td> </tr>");}echo("[<a href=\"index.php?id=newscom&view=addcomment&acl=$id\">Add a comment</a>]"); // add a commentbreak;case 'addcomment': // page for adding comments news_comments.php?view=addcomment&id=&idob_start(); // cookiesinclude("config.php"); // includes the config file$id = $_GET['acl']; // grabs the news idif(isset($_POST['add_comment'])) { // if the form has been submitted we query the db$author = $logged['username']; // comments author$postdate = date("g:i A, l F j"); // comments date$content = $_POST[content]; // comment$nid = $_GET['acl']; // news id$sql = "INSERT INTO news_comments ( `author` , `postdate`, `content`, `nid`) VALUES ('$author', '$postdate', '$comment', '$nid')"; // query for adding the comment$addblog = mysql_query($sql) // query?s the dbor die(mysql_error()); // error!header("Location: index.php"); // redirects the user}else // the form has not been submitted so we display it{echo ("<form method=\"post\" name=\"addcomment\"><tr> <td height=\"20\">Comment:</td></tr><tr> <td><br><textarea rows=\"5\" cols=\"35\" name=\"content\">Type your comment here!</textarea><br> <input type=\"submit\" name=\"add_comment\" value=\"Submit\"></td></tr></form>");}}if (!isset($_GET['id'])) // if there is not requested id we redirect the userheader("Location:index.php?id=news"); // goto news.php}else{echo('Hey! you need to [<a href=http://vexxon.net/login.php>login</a>] first!'); // user is not logged in so they are asked to.');}?>[/code]And my link system is not working either, here is the code for it:[code]<?phpob_start(); // allows us to use cookiesinclude("config.php"); // includes the config fileif(!$logged[username]) {header("Location:http://vexxon.net"); // if they arent logged in or dont have admin powers they are redirected}function cleanlink($url) {$filter = array("http://" => "","www." => "",);foreach ($filter as $remove => $stay) {$url = str_replace($remove, $stay, $url);}$filterurl = explode("/", $url);$bombedurl = $filterurl[0];$url = "http://";$url .= "$bombedurl";$url .= "/";return $url;}if(isset($_POST['submit'])) {$title=$_POST['title'];$url= cleanlink($_POST['url']);$description=$_POST['description'];$sql = mysql_query("INSERT INTO `links` ( `title` , `url` , `description` ) VALUES ('$title', '$url', '$description');"); // adds the link to the dbheader("Location:http://www.vexxon.net/index.php?id=links");}else {?><form method="post" name="links"><table width="52%" height="459" border="0"><tr><td valign="top">Links Title: </td><td valign="top"><input name="title" type="text"></td></tr><tr><td valign="top">Links URL: </td><td valign="top"><input name="url" type="text" value="http://"></td></tr><tr><td height="85" valign="top">Description: <br> </td><td valign="top"><textarea cols="50" rows="20" name="description"></textarea></td></tr><tr><td height="25" valign="top"> </td><td valign="top"><input type="submit" name="submit" value="Submit Link"></td></tr></table></form><?}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12339-bbcode-among-other-things/ Share on other sites More sharing options...
wildteen88 Posted June 19, 2006 Share Posted June 19, 2006 Try this:[code]function bbcode($content){ $bbcode = array( "'\[b\](.*?)\[/b\]'", "'\[i\](.*?)\[/i\]'", "'\[u\](.*?)\[/u\]'", "'\[code\](.+?)\[/code\]'", "'\[url=(.*?)\](.*?)\[/url\]'", "'\[url\](.*?)\[/url\]'", "'\[img\](.*?)\[/img\]'", ); $html = array( "<b>\\1</b>", "<i>\\1</i>", "<u>\\1</u>", "<strong>Code:</strong><div style=\"margin:0px 10px;padding:5px;border:1px dotted #FFFFFF;width:80%;\"></em>\\1</em></div>", "<a href=\"\\1\" target=\"_BLANK\">\\2</a>", "<a href=\"\\1\" target=\"_BLANK\">\\1</a>", "<img border=\"0\" src=\"\\1\">", ); $content = preg_replace($bbcode, $html, $content); // call a dedicated function to highlight our php code. $content = preg_replace_callback("#\[php\](.*?)\[\/php\]#is", 'highlight_php', $content); return nl2br($content);}function highlight_php($matches){ $php = "<strong>PHP:</strong><div style=\"margin:0px 10px;padding:5px;border:1px dotted #FFFFFF;width:80%;\"></em>"; $php .= highlight_string($matches[0], true); $php .= '</em></div>'; //strip out line breaks: $php = str_replace("<br />", '', $php); // strip out PHP BBCode tags: $php = preg_replace("#(\[php\]|\[/php\])#i", "", $php); return $php;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12339-bbcode-among-other-things/#findComment-47237 Share on other sites More sharing options...
Rosst Posted June 20, 2006 Author Share Posted June 20, 2006 [!--quoteo(post=385559:date=Jun 19 2006, 05:10 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 19 2006, 05:10 AM) [snapback]385559[/snapback][/div][div class=\'quotemain\'][!--quotec--]Try this:[code]function bbcode($content){ $bbcode = array( "'\[b\](.*?)\[/b\]'", "'\[i\](.*?)\[/i\]'", "'\[u\](.*?)\[/u\]'", "'\[code\](.+?)\[/code\]'", "'\[url=(.*?)\](.*?)\[/url\]'", "'\[url\](.*?)\[/url\]'", "'\[img\](.*?)\[/img\]'", ); $html = array( "<b>\\1</b>", "<i>\\1</i>", "<u>\\1</u>", "<strong>Code:</strong><div style=\"margin:0px 10px;padding:5px;border:1px dotted #FFFFFF;width:80%;\"></em>\\1</em></div>", "<a href=\"\\1\" target=\"_BLANK\">\\2</a>", "<a href=\"\\1\" target=\"_BLANK\">\\1</a>", "<img border=\"0\" src=\"\\1\">", ); $content = preg_replace($bbcode, $html, $content); // call a dedicated function to highlight our php code. $content = preg_replace_callback("#\[php\](.*?)\[\/php\]#is", 'highlight_php', $content); return nl2br($content);}function highlight_php($matches){ $php = "<strong>PHP:</strong><div style=\"margin:0px 10px;padding:5px;border:1px dotted #FFFFFF;width:80%;\"></em>"; $php .= highlight_string($matches[0], true); $php .= '</em></div>'; //strip out line breaks: $php = str_replace("<br />", '', $php); // strip out PHP BBCode tags: $php = preg_replace("#(\[php\]|\[/php\])#i", "", $php); return $php;}[/code][/quote]You are the greatest, it worked, to see it go to www.vexxon.net/index.php?id=news Quote Link to comment https://forums.phpfreaks.com/topic/12339-bbcode-among-other-things/#findComment-47536 Share on other sites More sharing options...
newb Posted June 20, 2006 Share Posted June 20, 2006 ur CMS is cool. do u mind sharing the script wen ur done. i wud like to use it. Quote Link to comment https://forums.phpfreaks.com/topic/12339-bbcode-among-other-things/#findComment-47538 Share on other sites More sharing options...
Rosst Posted June 20, 2006 Author Share Posted June 20, 2006 Hey, I would love to share the usersystem, when I'm done, anyway, can anyone help me with the other things? Quote Link to comment https://forums.phpfreaks.com/topic/12339-bbcode-among-other-things/#findComment-47774 Share on other sites More sharing options...
Rosst Posted June 20, 2006 Author Share Posted June 20, 2006 Some one please help me with this:<?phpinclude("config.php");include("include/bbcode.php");$sql = mysql_query("SELECT*FROM `tuts_cats` ORDER BY id DESC");if (!$_GET['cat']) {if (mysql_num_rows($sql) == 0) {echo "No tutorial categories";}else {echo "<table border=0 width=100%>";while ($r=mysql_fetch_array($sql)) {echo ("<tr><td><a href=\"index.php?id=tuts&cat=$r[category]\">$r[category]</td></tr>");}echo "</table>";}}elseif ($_GET['cat']) {$cat = $_GET['cat'];$sql2 = mysql_query("SELECT*FROM `tuts` where cat = '$cat' ORDER BY id DESC");if (mysql_num_rows($sql) == 0) {echo "No tutorials in this category";}else {echo "<table border=0 width=100%>";while ($r2=mysql_fetch_array($sql2)) {echo ("<tr><td><a href=\"index.php?id=tuts&tut=$r2[id]\">$r2[tutname]</td></tr><tr><td>$r2[description]</td></tr>");}echo "</table>";}}else {$tut = $_GET['tut'];$sql3 = mysql_query("SELECT*FROM `tuts` where id = '$tut'");$r3 = mysql_fetch_array($sql3);$content = bbcode($r3[content]);echo "<table border=0><tr><td>$r3[title] written by <a href=\"index.php?id=memb&user=$r3[author]\">$r3[author]</a></td></tr><tr><td>$r3[description], $r3[tutdate]</td></tr><tr><td>$content</td></tr></table>");}?> Quote Link to comment https://forums.phpfreaks.com/topic/12339-bbcode-among-other-things/#findComment-47825 Share on other sites More sharing options...
wildteen88 Posted June 21, 2006 Share Posted June 21, 2006 OKay can you explain in more detail what that code you posted is supposed to do and what it is currently doing. Without that information how are we supposed to know what to suggest in order to solve this problem. Quote Link to comment https://forums.phpfreaks.com/topic/12339-bbcode-among-other-things/#findComment-47975 Share on other sites More sharing options...
Rosst Posted June 21, 2006 Author Share Posted June 21, 2006 The code is my view category, and view tutorial code, it's not working, when I go to the link it shows nothing, observe: www.vexxon.net/includes/tutorials.php Quote Link to comment https://forums.phpfreaks.com/topic/12339-bbcode-among-other-things/#findComment-48212 Share on other sites More sharing options...
wildteen88 Posted June 22, 2006 Share Posted June 22, 2006 if you have no output then it loos like there is an error in your script check your servers error logs to see what the error might be. Quote Link to comment https://forums.phpfreaks.com/topic/12339-bbcode-among-other-things/#findComment-48421 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.