strago Posted February 28, 2015 Share Posted February 28, 2015 Is it possible to add this code function showBBcodes($db_pagetext) { // BBcode array $find = array( '~\[b\](.*?)\[/b\]~s', '~\[i\](.*?)\[/i\]~s', '~\[u\](.*?)\[/u\]~s', '~\[quote\](.*?)\[/quote\]~s', '~\[size=(.*?)\](.*?)\[/size\]~s', '~\[color=(.*?)\](.*?)\[/color\]~s', '~\[url\]((?:ftp|https?)://.*?)\[/url\]~s', '~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s' ); // HTML tags to replace BBcode $replace = array( '<b>$1</b>', '<i>$1</i>', '<span style="text-decoration:underline;">$1</span>', '<pre>$1</'.'pre>', '<span style="font-size:$1px;">$2</span>', '<span style="color:$1;">$2</span>', '<a href="$1">$1</a>', '<img src="$1" alt="" />' ); // Replacing the BBcodes with corresponding HTML tags return preg_replace($find,$replace,$db_pagetext); } in the code below? <?php $records_per_page = 500; $query = $_GET['thread']; $q2 = str_replace('-', ' ', $query); mysql_connect("localhost", "root", "password") or die(mysql_error()); mysql_select_db("DATABASE") or die(mysql_error()); //Get the page string $page = isset($_GET['thread']) ? mysql_real_escape_string(trim($_GET['thread'])) : ''; if(!empty($page)) { //Create the BASE query $FROM = "FROM post WHERE `threadid` = '$query'"; //Create and execute query to get total count of records $query = "SELECT COUNT(*) {$FROM}"; $result = mysql_query($query) or die(mysql_error()); $total_records = mysql_result($result, 0); $total_pages = ceil($total_records / $records_per_page); //Get selected page (or set to page 1) $page = isset($_GET['page']) ? intval($_GET['page']) : 1; //Ensure page is between 1 and total pages $page = max(min($total_pages, $page), 1); //Calc limit start value $limit = ($page - 1) * $records_per_page; //Create and execute query to get current page's records $query = "SELECT threadid, title, postid, username, dateline, pagetext {$FROM} ORDER by `postid` ASC LIMIT {$limit}, {$records_per_page}"; $result = mysql_query($query) or die(mysql_error()); $grab = mysql_fetch_array($result); echo "<html><head><title>Title - $grab[title]</title> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> </head><body> <H1>$grab[title]</H1>"; //Determine if there were results if(!mysql_num_rows($result)) { echo "No results"; } else { //Create results output mysql_data_seek($result, 0); while ($row = mysql_fetch_assoc($result)) { $db_pagetext = $row["pagetext"]; //http://www.digitcodes.com/create-simple-php-bbcode-parser-function/ $db_pagetext = str_ireplace('[i]', '<i>', $db_pagetext); $db_pagetext = str_ireplace('[/i]', '</i>', $db_pagetext); $db_pagetext = str_ireplace('[b]', '<b>', $db_pagetext); $db_pagetext = str_ireplace('[/b]', '</b>', $db_pagetext); $db_pagetext = str_ireplace('[u]', '<u>', $db_pagetext); $db_pagetext = str_ireplace('[/u]', '</u>', $db_pagetext); $results[]="<HR>Posted by {$row['username']}<P>$db_pagetext"; } echo implode("<br>\n", $results); } } echo `Footer text goes here.` ?> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 28, 2015 Share Posted February 28, 2015 Paste that function into your code or save it to another php file and include it, preferably before this line if(!empty($page)) Then replace these liines db_pagetext = str_ireplace('[i]', '<i>', $db_pagetext); $db_pagetext = str_ireplace('[/i]', '</i>', $db_pagetext); $db_pagetext = str_ireplace('[b]', '<b>', $db_pagetext); $db_pagetext = str_ireplace('[/b]', '</b>', $db_pagetext); $db_pagetext = str_ireplace('[u]', '<u>', $db_pagetext); $db_pagetext = str_ireplace('[/u]', '</u>', $db_pagetext); With the call to the showBBcodes function $db_pagetext = showBBcodes($db_pagetext); 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.