BBCode
Written by: maffelu , 2009-06-10 13:38:55
button and the text that is marked is magically turned into text), but this is just graphical and provides no help when it comes to actually working with the bbcode. Many users are today aware of BBCodes existance and can enter the [b] themselves. If you want a GUI(graphical user interface) for you users, look in the javascript section of morkalork for more information.
function simpleBBcode($text)
{
//This is what we're looking for
$search = array("[b]", "[/b]", "[i]", "[/i]", "[u]", "[/u]", "[title]", "[/title]");
//This is what we replace it with
$replace = array("<b>", "</b>", "<i>", "</i>", "<u>", "</u>", "<h2>", "</h2>");
//We use str_replace to make it easy
$text = str_replace($search, $replace, $text);
//We return the formatted text
return $text;
}
<?php
$text = '[title]Hello world![/title]<br />';
$text .= 'My name is [b]maffelu[/b] and I [u]love[/u] this page!<br />';
$text .= '[i]For the horde![/i]<br />';
$text = simpleBBcode($text);
echo $text;
?>
function bbcode($text)
{
//This is what we're looking for
$search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[title](.*?)\[\/title\]/is'
);
//This is what we replace it with
$replace = array(
'<strong>$1</strong>', //Bold text
'<em>$1</em>', //Italic text
'<u>$1</u>', //Underlined text
'<h2>$1</h2>' //Header text
);
//We use preg_replace since we're dealing with regexp
$text = preg_replace ($search, $replace, $text);
//We return the formatted text
return $text;
}
function bbcode($text)
{
//This is what we're looking for
$simple_search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[url\=(.*?)\](.*?)\[\/url\]/is',
'/\[color\=(.*?)\](.*?)\[\/color\]/is',
'/\[size\=(.*?)\](.*?)\[\/size\]/is',
'/\[title](.*?)\[\/title\]/is',
'/\[img](.*?)\[\/img]/is'
);
//This is what we replace it with
$simple_replace = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<a href="$1" target="_blank">$2</a>',
'<span style="color:$1">$2</span>',
'<span style="font-size:$1px">$2</span>',
'<h2>$1</h2>',
'<img src="$1" alt="image$1" border="0">'
);
//We use preg_replace since we're dealing with regexp
$text = preg_replace ($search, $replace, $text);
//We return the formatted text
return $text;
}
| BBCode | Html | Example |
|---|---|---|
| [b] | <b> | [bold]bold text[bold] |
| [i] | <i> | [italic]italic text[italic] |
| [u] | <u> | underlined text |
| [url=http://www.google.com]Google[/url] | <a href="http://www.google.com">Google</a> | |
| [color=#F00]Red [/color]text | <span style="color: red;">Red </span>text | Red text |
| [size=10]Small[/size] text | <span style="font-size: 10px;">Small</span> text | Small text |
| [title]A title[/title] | <h2>A title</h2> | A title |
| [img]Smiley6.gif[/img] | <img src="Smiley6.gif"> | ![]() |
There are 4 comments on this article.
player
2012-01-19 19:14:17
ifjEah http://exo.at.ua/load/52-2-2 http://www.phorumka.ru/forum/139-5987-1 http://www.bychkiv.net/index.php?showforum=37&prune_day=100&sort_by=Z-A&sort_key=last_post&topicfilter=all&st=150" http://malinor.ru/pleers/gom/159-xp-metallic.html http://kazachya.net/2010/04/19/page/2/
player
2012-01-20 04:26:59
oRJ0NK http://exo.at.ua/load/52-2-2 http://www.phorumka.ru/forum/139-5987-1 http://www.bychkiv.net/index.php?showforum=37&prune_day=100&sort_by=Z-A&sort_key=last_post&topicfilter=all&st=150" http://malinor.ru/pleers/gom/159-xp-metallic.html http://kazachya.net/2010/04/19/page/2/
Fymlwnvb
2012-02-06 05:37:24
I'm a trainee <a href=" http://www.netvibes.com/ahucoyfu#Little_lollita_girls_model ">little lollita girls model</a> 450404 <a href=" http://www.netvibes.com/igedibaup#Tarjetas_cachondas_lolitas_incesto ">models lolitas photo gallery</a> 7545 <a href=" http://www.netvibes.com/ilokosyla#Top_sexlola_net_bbs ">lolita nonude upskirt free</a> >:OOO <a href=" http://www.netvibes.com/mygoohe#Lolitas_peludas_culitos_abiertos ">lolitas girls tgp net</a> 4575 <a href=" http://www.netvibes.com/fuymihuku#Lolita_pics_russian_preteen ">lolita pics russian preteen</a> 4007 <a href=" http://www.netvibes.com/iginehoke#100_non_nude_lolitas ">adult lolita nude art</a> 504 <a href=" http://www.netvibes.com/arihoqeqy#Tiny_world_pussy_lolita ">very young pregnant lolita</a> %) <a href=" http://www.netvibes.com/efycogybul#Pre_teen_lolita_incest ">free nude loli pics </a> =-PP <a href=" http://www.netvibes.com/ubebecyfu#10_years_naked_lolita ">lolita preteen sex photos</a> 7441 <a href=" http://www.
If you have any question or just want to leave a message, just fill out the form below!
Your e-mail will not be visible in your post, it is for validation reasons only
Maffelu
Creator and admin of MorkaLork.com.
Started programming in HTML back when frames and tables was the way to design a page, moved on to Pascal/Delphi, PHP, javascript/jQuery, VB.NET/C#, Java and C++.
Currently studies .NET (in general) focusing on ASP.NET.
willem
2011-04-09 12:56:29
Very interesting. I tried to implement the script on my php guestbook, but have problems. I made the script into abbcode.js file and then put <script type="text/javascript" src="bbcode.js"></script> in the HEAD section.
But it does not work. Look here:
http://brasotadutchclub.org/news/index.php
What am I doing wrong?
Hope you will help me.