NoSalt Posted December 23, 2008 Share Posted December 23, 2008 I am working on a site where users can add comments. I have, naturally, stripped any HTML characters out of any user inputs but I would like to give them the ability to use some html (e.g., lists, bold, italics, etc.) I could use BBCode but I was reading on php.net that it is only supported under PHP 5.x and my hosting provider only has PHP 4.x. Another route I was thinking of would be like what is used on Reddit where you can add some mark (e.g., **, '', etc.) that I could translate into HTML on my own. What is the opinion of the PHPFreaks community? Any and all opinions will be welcomed. Thanks for reading Quote Link to comment https://forums.phpfreaks.com/topic/138181-solved-to-bbcode-or-not-to-bbcode-that-is-my-question/ Share on other sites More sharing options...
RichardRotterdam Posted December 23, 2008 Share Posted December 23, 2008 BBCode is not PHP version dependant. it's not even PHP dependant. Quote Link to comment https://forums.phpfreaks.com/topic/138181-solved-to-bbcode-or-not-to-bbcode-that-is-my-question/#findComment-722331 Share on other sites More sharing options...
NoSalt Posted December 23, 2008 Author Share Posted December 23, 2008 I was reading this: http://us3.php.net/manual/en/book.bbcode.php Quote Link to comment https://forums.phpfreaks.com/topic/138181-solved-to-bbcode-or-not-to-bbcode-that-is-my-question/#findComment-722335 Share on other sites More sharing options...
redarrow Posted December 23, 2008 Share Posted December 23, 2008 here a BBCODE it easy <?php $string = "I [i]am[/i] so [b]cool[/b] "; $bb_replace = array('[b]','[/b]','[i]','[/i]'); $bb_replacements = array ('<b>','</b>','<i>','</i>'); $string = str_replace($bb_replace,$bb_replacements,$string); echo $string; ?> Quote Link to comment https://forums.phpfreaks.com/topic/138181-solved-to-bbcode-or-not-to-bbcode-that-is-my-question/#findComment-722344 Share on other sites More sharing options...
NoSalt Posted December 23, 2008 Author Share Posted December 23, 2008 here a BBCODE it easy <?php $string = "I [i]am[/i] so [b]cool[/b] "; $bb_replace = array('[b]','[/b]','[i]','[/i]'); $bb_replacements = array ('<b>','</b>','<i>','</i>'); $string = str_replace($bb_replace,$bb_replacements,$string); echo $string; ?> So then your opinion is that BBCode is the way to go? Quote Link to comment https://forums.phpfreaks.com/topic/138181-solved-to-bbcode-or-not-to-bbcode-that-is-my-question/#findComment-722351 Share on other sites More sharing options...
redarrow Posted December 23, 2008 Share Posted December 23, 2008 added a little smiley image for you, So you no how it done ok. YES <?php $string = "<table><tr><td>I [i]am[/i] so [b]cool[/b]</td><td>[smile]</td> </td><tr></table>"; $bb_replace = array('[b]','[/b]','[i]','[/i]','[smile]'); $bb_replacements = array ('<b>','</b>','<i>','</i>','<img width="50px" height="30px" src="http://tbn2.google.com/images?q=tbn:kq6ay2cATrQg0M:http://www.teacherjoe.com/smiley2.gif">',' '); $string = str_replace($bb_replace,$bb_replacements,$string); echo $string; ?> Quote Link to comment https://forums.phpfreaks.com/topic/138181-solved-to-bbcode-or-not-to-bbcode-that-is-my-question/#findComment-722358 Share on other sites More sharing options...
premiso Posted December 23, 2008 Share Posted December 23, 2008 I am working on a site where users can add comments. I have, naturally, stripped any HTML characters out of any user inputs but I would like to give them the ability to use some html (e.g., lists, bold, italics, etc.) I could use BBCode but I was reading on php.net that it is only supported under PHP 5.x and my hosting provider only has PHP 4.x. Another route I was thinking of would be like what is used on Reddit where you can add some mark (e.g., **, '', etc.) that I could translate into HTML on my own. What is the opinion of the PHPFreaks community? Any and all opinions will be welcomed. Thanks for reading The reason people use BBCode is to store their data in it so it is parseable. This can be parsed by any language as long as you have it setup in a similiar manner. BBCode is universal just each site may have their own variations. Yep, I would go with BBCode. Quote Link to comment https://forums.phpfreaks.com/topic/138181-solved-to-bbcode-or-not-to-bbcode-that-is-my-question/#findComment-722362 Share on other sites More sharing options...
NoSalt Posted December 23, 2008 Author Share Posted December 23, 2008 Well ... thank you all for reading and replying. It looks like I'm going with BBCode then. redarrow ... thank you for the tips. Have a Happy Festivus everybody!!! Quote Link to comment https://forums.phpfreaks.com/topic/138181-solved-to-bbcode-or-not-to-bbcode-that-is-my-question/#findComment-722375 Share on other sites More sharing options...
redarrow Posted December 23, 2008 Share Posted December 23, 2008 Now i throw a spanner in the woods lol. There been a huge debaite in the programming world about using javascipt and ajax with bbcode. will the user have JavaScript on? I think you can add javascipt, and have the smiles and the bbcode do it all automatically, wrapping the bbcode around the words, but i beleve useing php on it own, is better dosent look better but you no every user got no browser confilcts. That the only thing you got to ask your self . Do i use javascript/ajax or just php. it being picky but it a debate world wide. Quote Link to comment https://forums.phpfreaks.com/topic/138181-solved-to-bbcode-or-not-to-bbcode-that-is-my-question/#findComment-722382 Share on other sites More sharing options...
NoSalt Posted December 23, 2008 Author Share Posted December 23, 2008 Just F.Y.I. ... Wikipedia has a good article on BBCode plus some links to BBCode implementations: http://en.wikipedia.org/wiki/BBCode Quote Link to comment https://forums.phpfreaks.com/topic/138181-solved-to-bbcode-or-not-to-bbcode-that-is-my-question/#findComment-722437 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.