- My projects about free energy, windmills, cnc routers, etc.

BBCode parser for comments

by funlw65 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.

Thank you Patric!

Tags · ·

posted in software

Related articles:

  • There are no related articles at this moment.

Comments:

funlw65 #1 funlw65 27.03.2008. 23:08

This text is formatted with BBCode function.
This is a quote:
This text is formatted with BBCode function.

pety #2 pety 28.03.2008. 02:51

Excelent!
Felicitari! Un sNews super dotat.

funlw65 #3 funlw65 28.03.2008. 05:14

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.

moshe #4 moshe 13.05.2008. 13:18

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

funlw65 #5 funlw65 13.05.2008. 14:56

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.

moshe #6 moshe 15.05.2008. 17:50

hey fun
thank you, downloaded
will learn from it.

awesome day

funlw65 #7 funlw65 16.05.2008. 03:17

If you have time to test it, please tell me how is working (speed, etc.). I know now is a FAT package Thank you

Write a comment

* = required field

:

:

:

:

Click to reload captcha image




Sponsors: