Jump to content

[SOLVED] Safetly Letting users use tags


cooldude832

Recommended Posts

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). 

Link to comment
Share on other sites

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;
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.