lostprophetpunk Posted August 16, 2008 Share Posted August 16, 2008 I am making a simple posting system. I have the following code to deal with the bbcode... function bbcode_format ($posted) { $posted = htmlentities($posted); $simple_search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is' ); $simple_replace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>' ); // Do simple BBCode's $posted = preg_replace ($simple_search, $simple_replace, $posted); return $_POST['entry']; } The data of '$posted' is then inserted into the database. But when I view the post on a different page, it hasn't worked. Am I doing something wrong? Quote Link to comment Share on other sites More sharing options...
marcus Posted August 16, 2008 Share Posted August 16, 2008 <?php function bbcode_format($posted) { $posted = htmlentities($posted); $simple_search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is' ); $simple_replace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>' ); // Do simple BBCode's $posted = preg_replace ($simple_search, $simple_replace, $posted); return $posted; } echo bbcode_format("[b][u][i]hello[/b][/u][/i]"); ?> Quote Link to comment Share on other sites More sharing options...
thebadbad Posted August 16, 2008 Share Posted August 16, 2008 If htmlentities() translates square brackets to their entity equivalent, the function won't work. Quote Link to comment Share on other sites More sharing options...
marcus Posted August 16, 2008 Share Posted August 16, 2008 Lol, there is no equivalence for the bracket. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted August 16, 2008 Share Posted August 16, 2008 Well, had to check now. There is indeed HTML entity equivalents for the square brackets ([ and ]), but htmlentities() doesn't translate them (at least not in PHP 5.2.2). So the OP is fine. 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.