Use BB Code in Your PHP Application

This is an article discussion thread for discussing the SitePoint article, “Use BB Code in Your PHP Application

Why use this when you can create HTML directly using many of the javascript/java WYSIWYG editors to plug into your textarea field? That way there is no learning curve at all.

I think that this method of BBCode is much too complex, it can be a lot simpler.

MarkDown or Textile would be better

Why do you think it’s complex? It’s only two lines.
On one line you create the parser object

$parser = new HTML_BBCodeParser();

and on the next one you parse the content

echo $parser->qParse($something_with_bb_in_it);

The rest is just more details on setup and customization.

I do agree with the statement about the learning curve. BB code may take some time to learn. But then why it is so widely used?

The drawbacks of the java* methods that I see (from personal experience) :

  • Javascript WYSIWYG textarea replacements are not cross-platform yet. They don’t work on Safari and Mac/IE
  • JAVA (tm :wink: applets are not free and/or have browser issues and/or are slow. To be honest, java support has been disabled in my browser for quite some time now. Actually, there’s a new Editize version (http://www.editize.com/), maybe it’s resolving those issues.

I think that installing PEAR and all the un-needed stuff is definately over the top, especially whent it isn’t needed.

BBCode you can easily do with regular expressions and it doesn’t require some extra application to do it.

OK, so the question is “to PEAR or not to PEAR?” (for relatively simpler tasks such as BB code parsing).
Not to PEAR:

  • unneeded setup
  • overhead
    To PEAR:
  • will do job faster
  • tested/maintained/bugfixed for you
  • no need to know regexps
  • easy to customize
  • error handling

To me PEAR is the better option even if I think only in terms of time. Say your client says “I want BB”. You can:
a/ go with PEAR and have it ready in like half an hour
b/ start coding regexps which can take day(s) provided you test as you should be
c/ find another lib which is less “expensive” in terms of memory and server space lib. The research and testing will probably take days
d/ steal the code from phpBB or another open-source project

Good article, thanks for sharing it. I was looking for somehting like this for quite a long time…

Thanks
Ravi

BBCode is used so people can’t exploit other people reading the forums with some kind of browser hole or a JavaScript exploit.

Also, it means you can easily change your “behind the screens” PHP without upsetting the design of the website.

BBCode is used so people can’t exploit other people reading the forums with some kind of browser hole or a JavaScript exploit.

This idea that BBCode helps to prevent cross-site scripting is both wrong and dangerous. In my opinion, BBCode is useless.

I might blog about this soon, since this is a growing misconception within the community that I want to properly address.

People that say you can do it with regex… yeah you can… BUT, some people already have done that for ya and have put it in this Pear package. The whole point of PEAR is to give you some pre-built tools for various tasks you may need one day. Use it and be happy.

Cross-Browser Rich Text Editor

http://www.kevinroth.com/rte/demo.htm

i think this will be much easier for end-user

Yes, such RTEs are great, but … again it doesn’t work on Mac IE or Safari :frowning:

I’ve been using HTMLArea (htmlarea.com) in a lot of my recent projects, and it works great. Works in IE and Mozilla based browsers (version 3 does anyway). As for Safari, are you serious? People still use that junk?

this only work when you are using your OWN server.

think about how to implement your application on web hosting site.

install extra packages === create unnecessary work!

Sometimes you don’t want to give your users fullpower over the html they can enter. Also with whatever RTE I used copy-pasting from an application like Word never works like you want it to, but simple users will try and do it anyway.

Using a BB formatting system you can easily limit the formatting options users have so everything will look as you want it to.

to flash:

I copied the code from the article AS IS on a $60/year web hosting service, I don’t know of any cheaper :wink:
http://www.w3clubs.com/sp/bb/
Feel free to play with it, it works just fine.
PEAR libs can run on a hosted service, no problem. Provided the functionality they give me, some sysadmin work is something I can live with.

It isn’t necessary to have PEAR set up by someone else when you are using shared hosting. There are several different methods you can use, but I would recommend using the manual installation process detailed in the pear manual (http://pear.php.net/manual/en/installation.manually.php).

It may take a little bit of work and time to get it set up and all, but in the long run I have found the PEAR packages to be a great resource and time-saver.

yes, the copy-paste won’t work on it, need to re-format the text.
but, i am not the one who volunteer to teach BB Code to ALL my users :sick:
especially most of they want “0” learning …