BBCode parser for comments
by on 27.03.2008. 22:56
I found a nice bb code parser in Article Script 1.1 of Johan Hornquist, which I`m using it in my comments. I disabled few options but still available others like:
[b]your text[/b] - bold
[i]your text[/i] - italic
[u]your text[/u] - underline
[align=(left|center|right)]your text[/align] - text alingment
[quote]your text[/quote] - quote
Here is the code:
<?php function BBCode($str) { //$str = nl2br(stripslashes($str)); $change = array( '/[b](.*?)[/b]/is', '/[i](.*?)[/i]/is', '/[u](.*?)[/u]/is', //'/[url=(.*?)](.*?)[/url]/is', //'/[url](.*?)[/url]/is', '/[align=(left|center|right)](.*?)[/align]/is', //'/[img](.*?)[/img]/is', //'/[font=(.*?)](.*?)[/font]/is', //'/[size=(.*?)](.*?)[/size]/is', '/[color=(.*?)](.*?)[/color]/is', //'/[code](.*?)[/code]/is', '/[quote](.*?)[/quote]/is', ); $with = array( '<strong>$1</strong>', '<em>$1</em>', '<span style="text-decoration: underline">$1</span>', //'<a href="$1">$2</a>', //'<a href="$1">$1</a>', '<div style="text-align: $1;">$2</div>', //'<img src="$1" />', //'<span style="font-family: $1;">$2</span>', //'<span style="font-size: $1;">$2</span>', '<span style="color: $1;">$2</span>', //'<code>$1</code>', '<span class="quote">$1</span>', ); $str = preg_replace($change, $with, $str); $str = bb_smilies($str); return $str; } ?>
It use Bakercad's function, bb_smilies, but you can disable that line.
For anyone who want to use html inside code tags, can use a tool from Patric's site. This tool prepare html code for displaying it in article as code.
posted in software
Related articles:
- There are no related articles at this moment.
Comments:
This text is formatted with BBCode function. ![]()
This is a quote:
This text is formatted with BBCode function.
![]()
Mai dureaza ceva timp pana va fi super dotat... Lista to do! e destul de mare...
Momentan, sunt multumit de parserul de cod bb si de cum a iesit combinatia cu codul lui Rui pentru zambaretii-butoane.
hey fun
very nice bb code
i love the design, and the look of comments, and icons
very well done.
you can make a new snews package like mu, su, etc..
karma++ 4 you ![]()
Thank you Moshe, I tried to make something for me
. But is disponible also for everybody.
you can make a new snews package like mu, su, etc..
Is a good idea to start with another package as you suggested. But maybe in Autumn...
I want to start an urgent project (my windmill) with the help of my father.
Until then, you can download my package from here, http://funlw65.googlepages.com/myblog.tar.gz . Tonight I will update it.
If you have time to test it, please tell me how is working (speed, etc.). I know now is a FAT package
Thank you
Sponsors:



Write a comment
* = required field