Dale Hay . com
Menu
Home
About
Contact
PHP Tutorials
BBCode
For Loop
Image Uploader
Message Board
Search Engine
Session Login
vidDetect
Photoshop Tutorials
Easy Clipart Style
Tech Stuff
HTML Friendly
MD5 Encrypter
SHA1 Encrypter
TGP Generator
Video Downloader
Web Affiliates
Web Linkbacks
Web Spam Emails
Random
Utilities
Learn Piano
Twinkle, Twinkle

PHP Tutorial - BBCode

Digg! This Page

Introduction

This tutorial will enable you to use BBCode (Bulletin Board Code) in either your own custom made forums, guestbooks or similar projects.

Step 1

For this example I'll start with a simple varible for the text, however you may have the text coming from the database.
Code:
<?php
$message = "[i]Hello[/i], my name is [b]Dale Hay[/b]";
?>

Step 2

Now we have the message as a variable I will show you how to turn the odd bits of stuff like [i][/i] and [b][/b] into formatted text. Below you will see an addition to my text that was entered above and that extra bit is basically the PHP to turn it from normal random weird text to HTML formatted text.
Code:
<?php
$message = "[i]Hello[/i], my name is [b]Dale Hay[/b]";
$message = str_replace("[b]", "<b>", $message);
$message = str_replace("[/b]", "</b>", $message);
$message = str_replace("[i]", "<i>", $message);
$message = str_replace("[/i]", "</i>", $message);
?>

The varible "$message" has been passed through all the coding and now to show it on a page all you have to do is print the "$message" varible.

Step 3

Now all you need to do is simply show the "updated" $message varible, by just printing it.
Code:
<?php
$message = "[i]Hello[/i], my name is [b]Dale Hay[/b]";
$message = str_replace("[b]", "<b>", $message);
$message = str_replace("[/b]", "</b>", $message);
$message = str_replace("[i]", "<i>", $message);
$message = str_replace("[/i]", "</i>", $message);
print $message;
?>

Your text should now have had changed into nicely formatted text. Like this: Hello, my name is Dale Hay.

Comments

Comments:

20th Jun 2007 20:13

Hi
By Ramin

21st Jun 2007 14:49

erm.. Hi.
By Dale Hay

25th Jun 2007 14:20

dude
By hey

17th Sep 2007 10:27

I just want to thankyou, I have been looking for a easy way and this help me out so much, all other bbcode script are so confusing, xudas.com TY!!!
By insanemonkey

17th Sep 2007 19:27

Glad it helped you "insanemonkey". I take it this is what you're using on your Xudas Forum?
By Dale Hay

17th Sep 2007 23:50

Wouldn't it be easier to use

preg_replace()

It would be faster and more flexible also.
By Marc N.

22nd Sep 2007 9:41

Using preg_replace() is yes, an easier way to do it however some people may get confused where to add the (*.?) or \1 stuff.
By Dale Hay

17th Dec 2007 9:32

awsome! thanks :D
By - Yakuza -

9th Feb 2008 11:55

http://www.xudas.com/index.php?page=tutorials?=bbcode_tutorial

So who wrote this you or this guy.

By Conrad

24th Feb 2008 8:31

I did Conrad, as the one on that site is from the comment replier "insanemonkey" who replied on the 17th September. That article you're pointing to was wrote on the 17th October ... a whole month later.
By Dale Hay

Add your comment...

Your Name:

Your Email:

Your Comment:

Enter This Number:

(44368)


Note: Your IP address is saved into the database when you submit a comment. Any type of threatening behaviour will result in your ISP being contacted and legal action being taken place!


Links
Audio Video Cables
My Other Sites
Sound Upload
UKtInfo
Budz
Feminine Hijinx
Martyn Coleman . com
SurfiOnline
Total Talent
Linux HOWTOs, Tutorials & Projects with Adam Palmer
Programs
dhSpy
Dale's Converter 1.1.1
DuMP
Other Links
Old Host: Servage
Latest News Stories
»
» No on 8!
» Atherstone Power Cut
»
» Happy 21st Birthday to Me!!
» Obama Wins
Top Viewed Stories
» Bypass Photobucket (22,130)
» Rare McDonalds Monopoly 2008 Tickets (7,916)
» PHP Mini Message Board Tutorial (5,781)
» PHP Search Engine Tutorial (3,245)
» Helen Willetts Pregnant? (2,383)
» QI Series 6 on BBC One (1,504)
Most Commented Stories
» PHP Mini Message Board Tutorial (43)
» Create your own Image Uploader (18)
» I like my DuMP (15)
» PHP Search Engine Tutorial (10)
» I'm on Wikipedia! (7)
» Chocie Munchin Niece (6)



Copyright Dale Hay, © 2005 - 2008