Jump to content

BB-codes ?


Sami

Recommended Posts

How can I make my website support BB-codes? :)(Oops, I just tough I should look for any existing topics about this, but I can't find out how to delete this one)

Link to comment
Share on other sites

An example:

preg_replace('/\[b\](.*?)\[\/b\]/is', '<b>$1</b>', $txt);

Notice how the square brackets are escaped. They normally contain a character class, but we want it to match the literal "[" character this time. "$1" represents the text within the parentheses in the regex.Tags like this are fairly simple to do, but image tags and similar tags are much more complex. The bbcode extension would be easier to use, but many hosts do not have it installed, nor would install it at your request. I was in your shoes once, and I checked with numerous hosts. None of them had the extension installed, and only a couple would install at your request. PEAR (a PHP library) has a class for it: http://pear.php.net/package/HTML_BBCodeParser

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...