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

free web hosting
Open Discussion > CONTRIBUTE > Computers > Database

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

iGuest
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.

Recent Queries:-
  1. bbcode using php functions - 8.73 hr back. (1)
  2. bbcode php - 8.48 hr back. (2)
  3. php bbcode parser - 30.34 hr back. (1)
  4. bbcode font-size php - 32.66 hr back. (1)
  5. bbcodes php function - 46.01 hr back. (1)
  6. bbcode in php - 50.88 hr back. (1)
  7. how to write html bbcode? - 51.75 hr back. (1)
  8. how to write bbcode - 52.91 hr back. (1)
  9. bbcode parser pro - 56.43 hr back. (1)
  10. bbcode php free code - 60.80 hr back. (1)
  11. php bbcode forum - 80.80 hr back. (1)
  12. make your own bbcode php list - 89.19 hr back. (1)
  13. php class bbcode - 91.82 hr back. (1)
  14. php bbcode function - 81.01 hr back. (2)
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,

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for php, bbcode, bbcode, forum, website, news,

*MORE FROM TRAP17.COM*
advertisement



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



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
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