May 17, 2008

Php Bbcode - bbcode for your forum/website/news..

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Database

free web hosting

Php Bbcode - bbcode for your forum/website/news..

Blessed
A simple BBcode class

CODE
<?php
//    Filename: bbcode.php
//    Version:     0.1
//

class bbcode {

    function code_box($text)
    {
        $output = "<div class=\"code\"><h6>Code</h6>\\1</div>";
    
    return $output;
    
    }

    function quote($text)
    {
        $output = "<blockquote><h6>Quote:</h6>\\1</blockquote>";
    
    return $output;
    
    }
    
    function htmlout($text)
    {
        $text = stripslashes($text);
        $text = htmlspecialchars($text);    
        $text = nl2br($text);
                
        return $text;
    }


    function parse($text)  
    {
        // First: If there isn't a "[" and a "]" in the message, don't bother.
        $text = " " . $text;
        if (! (strpos($text, "[") && strpos($text, "]")) )
        {
            return $text;    
        }
        else
        {
            // de uiteindelijke code
            $text = $this->htmlout($text);
        
            $text = preg_replace("/\\[b\\](.+?)\[\/b\]/is",'<b>\1</b>', $text);
            $text = preg_replace("/\\[i\\](.+?)\[\/i\]/is",'<i>\1</i>', $text);
            $text = preg_replace("/\\[u\\](.+?)\[\/u\]/is",'<u>\1</u>', $text);
            $text = preg_replace("/\[s\](.+?)\[\/s\]/is",'<s>\1</s>', $text);
            
            $text = preg_replace("/\[code\](.+?)\[\/code\]/is","".$this->code_box('\\1')."", $text);
            $text = preg_replace("/\[quote\](.+?)\[\/quote\]/is","".$this->quote('\\1')."", $text);
    
            $text = eregi_replace("\\[img]([^\\[]*)\\[/img\\]","<img src=\"\\1\">",$text);  
            $text = eregi_replace("\\[size([^\\[]*)\\]([^\\[]*)\\[/size\\]","<font size=\"\\1px\">\\2</font>",$text);
            $text = eregi_replace("\\[color=([^\\[]*)\\]([^\\[]*)\\[/color\\]","<font color=\"\\1\">\\2</font>",$text);    
            return $text;
        }    
    }
}

?>

Example

CODE
<?php
include('bbcode.php');
$bbcode = new bbcode;

$my_content = '[b]This is Bold[/b], [s]Strike[/s]';

$bbcode->parse($my_content);
?>


Have fun

if you want me to add more options feel free to ask

 

 

 


Reply

matak
Here's something that i accidentally discovered a while back smile.gif
How to write with bbcode...

CODE
<?php

$mycode = '<?php echo("hello");?> [b]<html>[/b]';

$stvarno = array ("<", ">", "[b]", "[/b]");

$zamjenjeno = array ("&lt;","&gt;", "<b>", "</b>");

$code = str_replace($stvarno, $zamjenjeno, $mycode);

echo ("$code");

?>


Here's the link to the topic.

I see that you are using a bunch of code for that, and i would like to hear advantages of coding that way. Looks like OOP to me. A thing i'll need to learn in near future. Thanks

 

 

 


Reply

Blessed
i this the bcode class is the siplest way
for the beginners

just include the file

Reply

Imtay22
Hey this is really cool i could use this on my site sometime! Only if I had a use for it... I see you only included the normal bbcodes. Maybe try in the next version adding some more advanced ones, like centered text, spoiler, and that kind of stuff. Thanks!

Reply

matak
I tried to output this code of yours but id didnt do nothing with this

CODE
<?php
include('bbcode.php');

$bbcode = new bbcode;

$my_content = '[b]This is Bold[/b], [s]Strike[/s]';


$bbcode->parse($my_content);
?>


What do i need to echo to get $my_content bbcoded!? Sorry i'm a oop newbie

Reply

Blessed
Try this

echo $bbcode->parse($my_content);

Reply

matak
QUOTE(Blessed @ Apr 13 2007, 05:24 PM) *
Try this

echo $bbcode->parse($my_content);


thanks. i feel stupid now blush.gif

Reply

Trap FeedBacker
Need a BB on my website http://www.notrac.net
Php Bbcode

Replying to Blessed

Need help to write a html code / bbcode that I can put on my website.

The members would like to write news on their profilepage without writing webmaster a mail. It don't have to be very pro but keep it simple.

Help? Please write to me by mail.

With kind regards

Vagabondo

-reply by Terje Jensen

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. bbcode php [quote] function - 0.80 hr back.
  2. php bbcode video - 5.73 hr back.
  3. bbcode php - 9.11 hr back.
  4. bbcode class php - 10.72 hr back.
  5. php bbcode class - 23.28 hr back.
  6. bbcode forum - 28.53 hr back.
Similar Topics

Keywords : php, bbcode, bbcode, forum, website, news,

  1. Forum Database
    Forum Database Space and its capacity to hold content (9)


      Looking for php, bbcode, bbcode, forum, website, news,

Searching Video's for php, bbcode, bbcode, forum, website, news,
advertisement



Php Bbcode - bbcode for your forum/website/news..



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE