cgm225 Posted September 8, 2008 Share Posted September 8, 2008 I want to allow users to leave comments on my website, and allow BBC in the comments. First, what actions should I be doing on the user provided data (i.e. the comment) to make sure its safe before I store it in my database and then for query when I display it on the website? Restated, how should I be filtering and/or validating the comment data? Also, how do I transform BBC into actual HTML elements when I output it to the website? Link to comment https://forums.phpfreaks.com/topic/123186-allowing-comments-on-website-how-should-i-validatefilter-the-input/ Share on other sites More sharing options...
Lodius2000 Posted September 8, 2008 Share Posted September 8, 2008 Also, how do I transform BBC into actual HTML elements when I output it to the website? us str_replace() with an array of bbc and an array of html, then input the comment string Link to comment https://forums.phpfreaks.com/topic/123186-allowing-comments-on-website-how-should-i-validatefilter-the-input/#findComment-636211 Share on other sites More sharing options...
cgm225 Posted September 8, 2008 Author Share Posted September 8, 2008 Are there BBC/HTML arrays already available out there somewhere? Link to comment https://forums.phpfreaks.com/topic/123186-allowing-comments-on-website-how-should-i-validatefilter-the-input/#findComment-636233 Share on other sites More sharing options...
xoligy Posted September 8, 2008 Share Posted September 8, 2008 this is my version of bbc that i found on the net check here it comes out better: http://pastebin.com/m2cfdfe16 Link to comment https://forums.phpfreaks.com/topic/123186-allowing-comments-on-website-how-should-i-validatefilter-the-input/#findComment-636240 Share on other sites More sharing options...
Lodius2000 Posted September 8, 2008 Share Posted September 8, 2008 so i assume you are running a strip_tags on the raw comment, incase someone does want to slip some html in there, that will leave you with just bbc, now make yourself a quick array of what you want to allow in your bbc like this $bbc = array("[b]", "[i]", "[h1]"); // add closing tags too then a replace with array $html = array("<b>", "<i>", "<h1>"); then $html_comment = str_replace($bbc, $html, $comment); now if somebody puts valid (meaning in your $bbc array) bbc in their comment then it replaces it, if it is invalid it stays as bbc and is displayed on the web as such, html would look like this <b>I think this is </b> [bad bbc] and print in the comment like: I think this is [bad bbc] Link to comment https://forums.phpfreaks.com/topic/123186-allowing-comments-on-website-how-should-i-validatefilter-the-input/#findComment-636300 Share on other sites More sharing options...
xoligy Posted September 8, 2008 Share Posted September 8, 2008 Just updated mine to add the smiles as mine was in a function called replace. To use the bbc you'd use something like below $txt = $row['post']; //where post is your comment $txt = replace($txt); Link to comment https://forums.phpfreaks.com/topic/123186-allowing-comments-on-website-how-should-i-validatefilter-the-input/#findComment-636315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.