SirChick Posted December 24, 2007 Share Posted December 24, 2007 I was wondering.. say a user wants to bold something in a forum: Some have: [b]Test[/b] then html uses: <b>Test</b> Now how do you make it so user input "allows" [b][/b] etc and also means when the text is echo'd it will be [b]bold[/b] ? Is it all done in html or is php involved too ? Will string escape function disallow it or does it allow it? Quote Link to comment Share on other sites More sharing options...
papaface Posted December 24, 2007 Share Posted December 24, 2007 <strong>text</strong> Not sure what you mean ??? Quote Link to comment Share on other sites More sharing options...
SirChick Posted December 24, 2007 Author Share Posted December 24, 2007 LOL my bad i put bold tags around it and forgot the code tags so it was just making the font bold so i guess it must of made me look a bit odd. Re-corrected now. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 24, 2007 Share Posted December 24, 2007 PHP is involved. It is bbcode. Search on google for it. Quote Link to comment Share on other sites More sharing options...
marcus Posted December 24, 2007 Share Posted December 24, 2007 <?php function bbcode_format($post) { $post = htmlentities($post); $simple_search = array( '/\[b\](.*?)\[\/b\]/is' ); $simple_replace = array( '<strong>$1</strong>' ); // Do simple BBCode's $post = preg_replace ($simple_search, $simple_replace, $post); return $post; } $post = "[b]hello[/b]"; $p = bbcode_format($post); echo $post."<br>"; echo $p."<br>"; ?> Quote Link to comment Share on other sites More sharing options...
SirChick Posted December 24, 2007 Author Share Posted December 24, 2007 <?php $simple_search = array( '/\[b\](.*?)\[\/b\]/is' ); $simple_replace = array( '<strong>$1</strong>' ); ?> Could you explain this part a bit... not sure i follow what thats doing ? Is it like a way to stop injection with bbcode ? Quote Link to comment Share on other sites More sharing options...
marcus Posted December 24, 2007 Share Posted December 24, 2007 It's escaping the brackets to be correct format for regex. Then if [b]text[/b] is found somewheres in the variable, it will replace it with the strong HTML. Quote Link to comment Share on other sites More sharing options...
SirChick Posted December 24, 2007 Author Share Posted December 24, 2007 Ok thankyou very much 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.