Jump to content

[SOLVED] To BBCode Or Not To BBCode ... That Is My Question


Recommended Posts

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

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

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?

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

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.

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.

 

 

 

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.