PHP_PhREEEk Posted December 3, 2007 Share Posted December 3, 2007 I won't be of much more help today... gotta get onto other things. Keep some rules in mind: 1. Never echo out HTML until you have everything you need to do so. Although it doesn't seem apparent, this will become a big issue later. So, don't echo some HTML, then do some PHP, then some more HTML, etc... Anything done with PHP should be stored in variables when possible, then, once we are sure a page is ready to go out, we echo out the header, the content, then the footer. 2. Whenever you send out a page, it goes: <?php include "header.php"; // echo your content include "footer.php"; 3. In order to utilize this in any of the other scripts, add define('IN_FORUM', true); to the top of said script, or you will be tossed back to index.php. 4. Repeat... keep all code separate from HTML, and keep the code at the top of the page when possible. Please replace all instances of 'print' with 'echo'. It's what we more or less prefer to use, and it's ingrained habit. I'll go crazy trying to remember to use print every time! heh Ok, I'll be back after I get some work done on this form I have promised to another user... he's been rather patient. PhREEEk Quote Link to comment Share on other sites More sharing options...
twsowerby Posted December 3, 2007 Author Share Posted December 3, 2007 Fantastic, you've been a great help! Will take your advice and go through and change some bits, look a hell of a lot tidier now! Thanks, Tom Quote Link to comment Share on other sites More sharing options...
twsowerby Posted December 6, 2007 Author Share Posted December 6, 2007 Ok I'm trying to implement this bbcode into the forum and I can't really get it to work. Code is: //BBcode Funtions function bb_format ($str) { $str = htmlentities($str); $bold_italic_underline_url_search = array ( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is' ); $bold_italic_underline_url_replace = array ( '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', '<a href="$1">$2</a>' ); $str = preg_replace ($bold_italic_underline_search, $bold_italic_underline_replace, $str); return $str; } I've got it sat in my functions.php file but when I call it it doesnt seem to be working. To be honest I dont really understand the way the code works so any pointers would be great. I know the basic concept is to take the tags inserted by the person writing the post and swap them with the proper html tags, but im not sure how to go about making it work. Cheers, Tom Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 7, 2007 Share Posted December 7, 2007 How are you 'calling' this? Let's see some example code... PhREEEk Quote Link to comment Share on other sites More sharing options...
twsowerby Posted December 7, 2007 Author Share Posted December 7, 2007 Not really sure how I'm meant to call it, so I tried this: <?php // File: message.php // define('IN_FORUM', true); include_once "sqlconnect.php"; include_once "includes/functions.php"; include "includes/header.php"; $id=$_GET['id']; echo "<link rel='stylesheet' href='style.css' type='text/css'>"; echo "<a href='index.php'>Back to main forum</a>-<A href='post.php'>New Topic</a>-<a href='reply.php?id=$id'>Reply<br>"; echo "<table class='maintable'>"; echo "<tr class='headline'><td width=20%>Author</td><td width=80%>Post</td></tr>"; $gettopic="SELECT * from forum_posts where postid='$id'"; $gettopic2=mysql_query($gettopic) or die("Could not get topic"); $gettopic3=mysql_fetch_array($gettopic2); echo "<tr class='mainrow'><td valign='top'>$gettopic3[author]</td><td valign='top'>Last replied to at $gettopic3[showtime]<br><hr>"; $message=strip_tags($gettopic3['post']); $message=nl2br($message); echo "$message<hr><br>"; echo "</td></tr>"; $getreplies="select * from forum_posts where parentid='$id' order by postid desc"; //getting replies $getreplies2=mysql_query($getreplies) or die("Could not get replies"); while($getreplies3=mysql_fetch_array($getreplies2)) { bb_format (echo "<tr class='mainrow'><td valign='top'>$getreplies3[author]</td><td valign='top'>Last replied to at $getreplies3[showtime]<br><hr>" $message=strip_tags($getreplies3['post']); $message=nl2br($message); echo "$message<hr><br>"; echo "</td></tr>"; } echo "</table>"; include "includes/footer.php"; ?> The bb_format (echo "<tr class='mainrow'><td valign='top'>$getreplies3[author]</td><td valign='top'>Last replied to at $getreplies3[showtime]<br><hr>" part is where i think it should go... Tom Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 7, 2007 Share Posted December 7, 2007 To use the BBCode function, assign the message coming out of the database to it, so like: $message=strip_tags($getreplies3['post']); would be: $message=strip_tags($getreplies3['post']); $message = bb_format($message); You do get what the bbcode is doing, right? PhREEEk Quote Link to comment Share on other sites More sharing options...
twsowerby Posted December 7, 2007 Author Share Posted December 7, 2007 Ok I'll try that. Yeah i tihnk so, it checks the record its retrieving for specific tags and then replaces them with the proper html tags so that the browser recognises what needs to be bold, italic, etc right? Tom Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 7, 2007 Share Posted December 7, 2007 there ya go... = ^) PhREEEk Quote Link to comment Share on other sites More sharing options...
twsowerby Posted December 7, 2007 Author Share Posted December 7, 2007 Cool it works now, thanks. Get some sleep dude, I'm sure I'll have encountered another obstacle by the time you wake up! Tom 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.