cooldude832 Posted October 20, 2007 Share Posted October 20, 2007 I have a field on my profile system that allows a users to put in a paragraph about themselves. I want to allow some very basic styling here (like returns, bold, color etc) is there a way I can add BB tags to this easily or some other method (I"ve never used BB tags before so if someone could point me in the right direction that be great). Quote Link to comment https://forums.phpfreaks.com/topic/74132-solved-safetly-letting-users-use-tags/ Share on other sites More sharing options...
MadTechie Posted October 21, 2007 Share Posted October 21, 2007 Heres a bbcode2html, as this board uses BBcode i have added @ signs to stop the parsing, your need to remove all of them.. <?php // A simple FAST parser to convert BBCode to HTML // Trade-in more restrictive grammar for speed and simplicty // // Syntax Sample: // -------------- // [@img]http://phpfreaks.com/images/deadrats.gif[@/img] // [@url="http://phpfreaks.com"]phpfreaks[@/url] // [@mail="webmasterphpfreaks.com"]Webmaster[@/mail] // [@size="25"]HUGE[@/size] // [@color="red"]RED[@/color] // [@b]bold[@/b] // [@i]italic[@/i] // [@u]underline[@/u] // [@list][*]item[*]item[*]item[@/list] // [@code]value="123";[@/code] // [@quote]John said yadda yadda yadda[@/quote] // // Usage: // ------ // <?php include 'bb2html.php'; ?> // <?php $htmltext = bb2html($bbtext); ?> function bb2html($text) { $bbcode = array("<", ">", "[@list]", "[*]", "[@/list]", "[@img]", "[@/img]", "[@b]", "[@/b]", "[@u]", "[@/u]", "[@i]", "[@/i]", '[@color="', "[@/color]", "[@size=\"", "[@/size]", '[@url="', "[@/url]", "[@mail=\"", "[@/mail]", "[@code]", "[@/code]", "[@quote]", "[@/quote]", '"]'); $htmlcode = array("<", ">", "<ul>", "<li>", "</ul>", "<img src=\"", "\">", "<b>", "</b>", "<u>", "</u>", "<i>", "</i>", "<span style=\"color:", "</span>", "<span style=\"font-size:", "</span>", '<a href="', "</a>", "<a href=\"mailto:", "</a>", "<code>", "</code>", "<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>", '">'); $newtext = str_replace($bbcode, $htmlcode, $text); $newtext = nl2br($newtext);//second pass return $newtext; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74132-solved-safetly-letting-users-use-tags/#findComment-374394 Share on other sites More sharing options...
pocobueno1388 Posted October 21, 2007 Share Posted October 21, 2007 as this board uses BBcode i have added @ signs to stop the parsing, your need to remove all of them.. I don't think it will parse the BBcode between [.code][./code] tags. So no need to worry about that in the future Just to test... [b]test[/b] Quote Link to comment https://forums.phpfreaks.com/topic/74132-solved-safetly-letting-users-use-tags/#findComment-374395 Share on other sites More sharing options...
MadTechie Posted October 21, 2007 Share Posted October 21, 2007 lets see <?php // A simple FAST parser to convert BBCode to HTML // Trade-in more restrictive grammar for speed and simplicty // // Syntax Sample: // -------------- // [img=http://phpfreaks.com/images/deadrats.gif] // [url="http://phpfreaks.com"]phpfreaks[/url] // [mail="webmasterphpfreaks.com"]Webmaster[/mail] // [size="25"]HUGE[/size] // [color="red"]RED[/color] // [b]bold[/b] // [i]italic[/i] // [u]underline[/u] // [list][*]item[*]item[*]item[/list] // [@code]value="123";[@/code] // [@quote]John said yadda yadda yadda[@/quote] // // Usage: // ------ // <?php include 'bb2html.php'; ?> // <?php $htmltext = bb2html($bbtext); ?> function bb2html($text) { $bbcode = array("<", ">", "[list]", "[*]", "[/list]", "[img=", "]", "[b]", "[/b]", "[u]", "[/u]", "[i]", "[/i]", '[color="', "[/color]", "[size=\"", "[/size]", '[url="', "[/url]", "[mail=\"", "[/mail]", "[@code]", "[/@code]", "[@quote]", "[/@quote]", '"]'); $htmlcode = array("<", ">", "<ul>", "<li>", "</ul>", "<img src=\"", "\">", "<b>", "</b>", "<u>", "</u>", "<i>", "</i>", "<span style=\"color:", "</span>", "<span style=\"font-size:", "</span>", '<a href="', "</a>", "<a href=\"mailto:", "</a>", "<code>", "</code>", "<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>", '">'); $newtext = str_replace($bbcode, $htmlcode, $text); $newtext = nl2br($newtext);//second pass return $newtext; } ?> got a feeling that the code and quote will mess it up... EDIT: Holy Hell, remove @ from quote and code Quote Link to comment https://forums.phpfreaks.com/topic/74132-solved-safetly-letting-users-use-tags/#findComment-374396 Share on other sites More sharing options...
cooldude832 Posted October 21, 2007 Author Share Posted October 21, 2007 Do you have the include 'bb2html.php' ?? Quote Link to comment https://forums.phpfreaks.com/topic/74132-solved-safetly-letting-users-use-tags/#findComment-374424 Share on other sites More sharing options...
MadTechie Posted October 21, 2007 Share Posted October 21, 2007 that is the file.. just add the function "bb2html" to your project (or add it to a file and include it) then use as anyother function.. Quote Link to comment https://forums.phpfreaks.com/topic/74132-solved-safetly-letting-users-use-tags/#findComment-374427 Share on other sites More sharing options...
cooldude832 Posted October 21, 2007 Author Share Posted October 21, 2007 so should I striptags then apply bb2html to be safe, as I do'nt want stray divs to show up and mess up output Quote Link to comment https://forums.phpfreaks.com/topic/74132-solved-safetly-letting-users-use-tags/#findComment-374428 Share on other sites More sharing options...
cooldude832 Posted October 21, 2007 Author Share Posted October 21, 2007 also do you have a reverse of this so that I can get it unbbed, I could store it unbbed in the database, but I prefer not to as this is a fairly large field Quote Link to comment https://forums.phpfreaks.com/topic/74132-solved-safetly-letting-users-use-tags/#findComment-374430 Share on other sites More sharing options...
cooldude832 Posted October 21, 2007 Author Share Posted October 21, 2007 The color field doesn't seem to be working? Quote Link to comment https://forums.phpfreaks.com/topic/74132-solved-safetly-letting-users-use-tags/#findComment-374437 Share on other sites More sharing options...
cooldude832 Posted October 21, 2007 Author Share Posted October 21, 2007 Never mind I solved it I needed to fix the slashes on it. Gotta love MQ. Anyway thanks a lot for that, I didn't realize that was how BB code worked. Quote Link to comment https://forums.phpfreaks.com/topic/74132-solved-safetly-letting-users-use-tags/#findComment-374443 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.