Jump to content

[SOLVED] bbcode


runnerjp

Recommended Posts

im trying to creat soe bbcode .. i have everything in place but the [q.uote] one!

 

i have looked all over but nowhere seems to have how to creat the quote class??

 

i can get it to show in my textbox like this

 

[q.uote=runnerjp]

this is the quote form my forum

[/q.uote]

 

but how do i add the bbcode to it so it looks something like this

 

this is the quote form my forum

Link to comment
Share on other sites

well, if i were you i'd just view the source of lots of pages that use [q.uote] tags and use that html, and the css usually isn't difficult to backward-engineer.

 

also, this: http://www.phpbuilder.com/board/showthread.php?t=10353882 may help you (third code block in the first post). that code uses preg_replace, but you may want to use str_replace.

i'm not sure how they get the name of the quotee (guy who's being quoted). you may have to explode the contents of the quote tag to get the name and then concatenate it somewhere.

 

hope this helps.

Link to comment
Share on other sites

not to sure how to implament it into my current code

 

<?php
class BBCode {
protected $bbcodes; // Store array of BBCodes
protected $vbbcodes; // Store array of Variable BBCodes
var $debug = ''; // Store any errors
var $selection = ''; // Store the selection to be parsed first
var $parsed = ''; // Store the parsed selection.
var $path2emoticon = 'http://www.runningprofiles.com/emoticons/'; // Set the path to the emoticon images.
var $imgext = '.gif'; // Set this to the ext of the images
public $emoticons = 
	array( '' => 'Roll Eyes', '' => 'Smiley', '' => 'Wink', '' => 'Cheesy', '' => 'Grin', '' => 'Angry',
	'' => 'Sad', '' => 'Shocked', '' => 'Cool', '???' => 'Huh', '' => 'Tongue', ':-[' => 'Embarrassed', 
	':-X' => 'Lips Sealed', ':-\\' => 'Undecided', '' => 'Kiss', ':*(' => 'Cry' ); 
	// All emoticons. Spaces and caps will be removed for image names.

function parseCode($security=0) { // Security defaults to 0. Set to 1 for non-variable bbcodes only.
	if(!$this->selection) { // Check if the user has set the selection.
		$this->debug .= "You must set a value for the selection before parsing! "; // Set the Debug variable if not.
	}else{
		if($this->parsed) { // Check if text has already been parsed.
			$this->debug .= "You must run the code parser before the emoticon parser! "; // Set the Debug variable if so.
		}else{
			$selection = str_replace("\n", '', $this->selection); // Set selection variable for inside function only.
			$selection2 = htmlentities(str_replace("\n", '', $this->selection)); // Remove html entities for security.
			$this->selectCodes($security); // Select codes depending on security.
			#### Start [code] Section ###
			preg_match_all("/\[code\].+\[\/code\]/Ui", $selection2, $matches); // Check for [code] tags. Set the matches array.
			$i = 0; // Set the variable to the default of 0.
			while(isset($matches[0][$i])) { // Check for match from preg_match.
				$selection = str_ireplace(html_entity_decode($matches[0][$i]), "[code$i]", $selection); // Decode and replace for strip tags.
				$i++; // Add one to the variable to loop.
			}
			$selection = strip_tags($selection); // Strip tags from the selection.
			while($i>0) { // Reloop through matches.
				$i--; // Remove one from the variable to loop.
				$m = html_entity_decode($matches[0][$i]); // Decode the match for accurate removal.
				$m = str_ireplace("[code]", "", $m); // Remove [code] tag.
				$m = str_ireplace("

", "", $m); // Remove [/code] tag.

$m = highlight_string($m,true); // Highlight string and encode.

$selection = str_ireplace("

[code$i]", "
" . $m . "

", $selection); // Add highlighted code back with tags for later parsing.

}

#### End

 Section ####
			### Start BBCode Section ###
			foreach ($this->bbcodes as $key => $value) { // Loop through bbcodes.
				$selection = str_ireplace($key, $value, $selection); // Replace the $key value(bbcode) with the $value value(html code).
			}
			#### End BBCode Section ###
			### Start Var. BBCode Sec. ##
			if($security==0) { // Only loop through if security allows it.
				foreach ($this->vbbcodes as $key => $value) { // Loop through variable bbcodes.
					unset($matches); // Unset matches set in earlier code.
					$i = 0; // Set the variable to the default of 0.
					preg_match_all($key, $selection, $matches); // Find all instances of the variable bbcode set them to matches.
					// Preg Matching also stores the "variables" inside the matches var. with the matches.
					while(isset($matches[0][$i])) { // Check if there are any instances.
						$v = str_replace("*", $matches[1][$i], $value); // Replace the asterisk with the variable value.
						if(isset($matches[2][$i])) { // Check for more than one variable.
							$v = str_replace("~", $matches[2][$i], $v); // Replace the ~ with the second variable value.
						}
						$selection = str_replace($matches[0][$i], $v, $selection); // Replace the match with the accumulated variable.
						$i++; // Add one to the variable to loop.
					}
				}
			}
			### End Var. BBCode Sec. ##
			$this->parsed = $selection; // Insert the accumulated parsed selection into the parsed variable as to keep selection original.
			unset($selection); // Remove all value from private variable selection.
		}
	}
}

protected function selectCodes($security=0) { // Security defaults to 0. Set to 1 for non-variable bbcodes only.
	switch ($security) { // Switch between 0 and 1.
		default: // In the case of security being anything but one. Defaulting to zero.
		case 0: // In the case of security being zero.
			$this->bbcodes =
				array( "[i]" => "<i>", "[/i]" => "</i>", "[b]" => "<b>", "[/b]" => "</b>", "[u]" => "<u>", "[/u]" => "</u>", "[s]" => "<del>", "[/s]" => "</del>", "[move]" => "<marquee>", "[/move]" => "</marquee>",
				"
[center]" => "<center>", "[/center]
" => "</center>", "[hr]" => "<hr />", "[table][tr][td]" => "<table>", "" => "</table>", "[table][tr][td]" => "<tr>", "[/td][/tr][/table]" => "</tr>", "[table][tr][td]" => "<td>",
				"[/td][/tr][/table]" => "</td>", "[sub]" => "<sub>", "[/sub]" => "</sub>", "[sup]" => "<sup>", "[/sup]" => "</sup>", "[tt]" => "<tt>", "[/tt]" => "</tt>", "[list]" => "<ul>", "[/list]" => "</ul>", "[list][*]" => "<li>",
				"[/list]" => "</li>", "[/size]" => "</font>", "[/face]" => "</font>", "[/color]" => "</font>", "[p]" => "<p>", "[/p]" => "</p>",
				"[/td][/tr][/table][code]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>", "

" => "</p>","

" => "<p style=\"background: #E2E2E2; border: 1px solid #99b3b4; padding: 6px;\"><span style=\"font: bold 10px Courier New;\"></span>", "
" => "</p>" );

// BBCode array including their replacement.

$this->vbbcodes =

array( "/\/Ui" => "<font size=\"*\">", "/\[face=(.+)\]/U" => "<font face=\"*\">", "/\/Ui" => "<font color=\"*\">", "/\[img\](.+)\[\/img\]/Ui" => "<img src=\"*\" />",

"/\[email\](.+)\[\/email\]/Ui" => "<a href=\"mailto:*\">*</a>", "/\[url\](.+)\[\/url\]/Ui" => "<a href=http://\*\>*</a>", "/\(.+)\[\/email\]/Ui" => "<a href=\"mailto:*\">~</a>",

"/\(.+)\[\/url\]/Ui" => "<a href=\"*\">~</a>" );

// Variable BBCode array including their replacement and variable position(s).

break;

case 1: // In the case of security being one.

$this->bbcodes =

array( "" => "<i>", "" => "</i>", "" => "<b>", "" => "</b>", "" => "<u>", "" => "</u>", "" => "<del>", "" => "</del>", "[move]" => "<marquee>", "[/move]" => "</marquee>",

"

" => "</center>", "" => "<hr />", "

" => "<table>", "" => "</table>", "
" => "<tr>", "
" => "</tr>", "
" => "<td>",

"

" => "</td>", "" => "<sub>", "" => "</sub>", "" => "<sup>", "" => "</sup>", "" => "<tt>", "" => "</tt>", "

" => "</ul>", "

" => "</li>", "

" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>",
				"

" => "</p>" ,"

" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>", "

" => "</p>");

// BBCode array including their replacement.

break;

}

}

 

function parseEmoticons($noBBCode=0) { // noBBCode variable defaults to 0. If set to one the parser will not parse be able to parse BBCode.

if(!$this->selection) { // Check if the user has set the selection.

$this->debug .= "You must set a value for the selection before parsing! "; // Set the Debug variable if not.

}else{

$error = 0; // Default to no errors.

if($this->parsed) { // If something has already been parsed.

$selection = str_replace("\n", '', $this->parsed); // Set the parsed value in order to not reset the already parsed selection.

}elseif($noBBCode==1) { // If nothing has been parsed and the noBBCode variable has been set to one.

$selection = str_replace("\n", '', $this->selection); // Set the selection value to variable selection.

$error = 2; // Set the error variable to 2 so that it will not look for

 tags.
		}else{ // If all else fails.
			$this->debug .= "You must parse BBCode first or set the noBBCode variable to 1(setting this variable will not allow bbcode to be parsed)! "; // Set the Debug variable if it gets here.
			$error = 1; // Set the error variable so the parser doesn't run.
		}
		if($error==0 or $error==2) {
			if($error==0) { // Only search if there has been parsing.
				unset($matches);
				preg_match_all('/\<p style="background: #BBBBBB; border: 1px solid #555555; padding: 6px;"\>.+\<\/p\>/Uim', $selection, $matches); // Finds all code selections.
				$i = 0; // Set the variable to the default of 0.
				while(isset($matches[0][$i])) { // Check for match from preg_match.
					$selection = str_ireplace($matches[0][$i], "[code$i]", $selection); // Replace for non-emoticon section.
					$i++; // Add one to the variable to loop.
				}
			}
			foreach($this->emoticons as $key => $value) { // For each emoticon set the key and value.
				$v = str_replace(" ", "", $value); // Remove all spaces from value but not replacing the value variable.
				$v = "<img src=\"" . $this->path2emoticon . strtolower($v) . $this->imgext . "\" alt=\"$value\" />"; // Set the image replacement up.
				$selection = str_ireplace($key, $v, $selection); // Replace the key with the set up image replacement.
			}
			if($error==0) { // Only search if there has been parsing.
				while($i>0) { // Reloop through matches.
					$i--; // Remove one from the variable to loop.
					$selection = str_ireplace("[code$i]", $matches[0][$i], $selection); // Add the codes back for final display.
				}
			}
			$this->parsed = $selection; // Insert the accumulated parsed selection into the parsed variable as to keep selection original.
			unset($selection); // Remove all value from private variable selection.
		}
	}
}
}
?>

Link to comment
Share on other sites

function bbcode_formation($mssg) {
$mssg = htmlentities($mssg);

     $formats = array(
                      '/\[quote=(.*?)\] (.*?)\[\/quote\]/is',
                      );
      $replacement = array(
                      '<div class="quote_title">$1</div><br /><div class="quote">$2</div>',
                      );

$mssg = preg_replace($formats, $replacement, $mssg);
return $mssg;
} 

Link to comment
Share on other sites

forget the bbclass. That function is all you need. $1, $2 are defining the two (.*?) which is the content the user enters, so don't touch them. just implement the function into your script and use it like this: bbcode_formation($string);

 

and you're done.

Link to comment
Share on other sites

hum i tried it and it didnt work!

 

here is my code on how i added it

<?php
class BBCode {
    protected $bbcodes; // Store array of BBCodes
    protected $vbbcodes; // Store array of Variable BBCodes
    var $debug = ''; // Store any errors
    var $selection = ''; // Store the selection to be parsed first
    var $parsed = ''; // Store the parsed selection.
    var $path2emoticon = 'http://www.runningprofiles.com/emoticons/'; // Set the path to the emoticon images.
    var $imgext = '.gif'; // Set this to the ext of the images
    public $emoticons = 
        array( '' => 'Roll Eyes', '' => 'Smiley', '' => 'Wink', '' => 'Cheesy', '' => 'Grin', '' => 'Angry',
        '' => 'Sad', '' => 'Shocked', '' => 'Cool', '???' => 'Huh', '' => 'Tongue', ':-[' => 'Embarrassed', 
        ':-X' => 'Lips Sealed', ':-\\' => 'Undecided', '' => 'Kiss', ':*(' => 'Cry' ); 
        // All emoticons. Spaces and caps will be removed for image names.
    
    function parseCode($security=0) { // Security defaults to 0. Set to 1 for non-variable bbcodes only.
        if(!$this->selection) { // Check if the user has set the selection.
            $this->debug .= "You must set a value for the selection before parsing! "; // Set the Debug variable if not.
        }else{
            if($this->parsed) { // Check if text has already been parsed.
                $this->debug .= "You must run the code parser before the emoticon parser! "; // Set the Debug variable if so.
            }else{
                $selection = str_replace("\n", '', $this->selection); // Set selection variable for inside function only.
                $selection2 = htmlentities(str_replace("\n", '', $this->selection)); // Remove html entities for security.
                $this->selectCodes($security); // Select codes depending on security.
                #### Start [c.ode] Section ###
                preg_match_all("/\[code\].+\[\/code\]/Ui", $selection2, $matches); // Check for [c.ode] tags. Set the matches array.
                $i = 0; // Set the variable to the default of 0.
                while(isset($matches[0][$i])) { // Check for match from preg_match.
                    $selection = str_ireplace(html_entity_decode($matches[0][$i]), "[code$i]", $selection); // Decode and replace for strip tags.
                    $i++; // Add one to the variable to loop.
                }
                $selection = strip_tags($selection); // Strip tags from the selection.
                while($i>0) { // Reloop through matches.
                    $i--; // Remove one from the variable to loop.
                    $m = html_entity_decode($matches[0][$i]); // Decode the match for accurate removal.
                    $m = str_ireplace("[c.ode]", "", $m); // Remove [c.ode] tag.
                    $m = str_ireplace("

", "", $m); // Remove [/code] tag.

                    $m = highlight_string($m,true); // Highlight string and encode.

                    $selection = str_ireplace("

[code$i]", "[c.ode]" . $m . "[/code]

", $selection); // Add highlighted code back with tags for later parsing.

                }

                #### End [co.de] Section ####

                ### Start BBCode Section ###

                foreach ($this->bbcodes as $key => $value) { // Loop through bbcodes.

                    $selection = str_ireplace($key, $value, $selection); // Replace the $key value(bbcode) with the $value value(html code).

                }

                #### End BBCode Section ###

                ### Start Var. BBCode Sec. ##

                if($security==0) { // Only loop through if security allows it.

                    foreach ($this->vbbcodes as $key => $value) { // Loop through variable bbcodes.

                        unset($matches); // Unset matches set in earlier code.

                        $i = 0; // Set the variable to the default of 0.

                        preg_match_all($key, $selection, $matches); // Find all instances of the variable bbcode set them to matches.

                        // Preg Matching also stores the "variables" inside the matches var. with the matches.

                        while(isset($matches[0][$i])) { // Check if there are any instances.

                            $v = str_replace("*", $matches[1][$i], $value); // Replace the asterisk with the variable value.

                            if(isset($matches[2][$i])) { // Check for more than one variable.

                                $v = str_replace("~", $matches[2][$i], $v); // Replace the ~ with the second variable value.

                            }

                            $selection = str_replace($matches[0][$i], $v, $selection); // Replace the match with the accumulated variable.

                            $i++; // Add one to the variable to loop.

                        }

                    }

                }

                ### End Var. BBCode Sec. ##

                $this->parsed = $selection; // Insert the accumulated parsed selection into the parsed variable as to keep selection original.

                unset($selection); // Remove all value from private variable selection.

            }

        }

    }

   

    protected function selectCodes($security=0) { // Security defaults to 0. Set to 1 for non-variable bbcodes only.

        switch ($security) { // Switch between 0 and 1.

            default: // In the case of security being anything but one. Defaulting to zero.

            case 0: // In the case of security being zero.

                $this->bbcodes =

                    array( "" => "<i>", "" => "</i>", "" => "<b>", "" => "</b>", "" => "<u>", "" => "</u>", "" => "<del>", "" => "</del>", "[move]" => "<marquee>", "[/move]" => "</marquee>",

                    "

" => "<center>", "

" => "</center>", "


" => "<hr />", "
" => "<table>", "" => "</table>", "
" => "<tr>", "
" => "</tr>", "
" => "<td>",

                    "

" => "</td>", "" => "<sub>", "" => "</sub>", "" => "<sup>", "" => "</sup>", "" => "<tt>", "" => "</tt>", "
  • " => "<ul>", "

" => "</ul>", "

  • " => "<li>",
                        "

" => "</li>", "[/size]" => "</font>", "[/face]" => "</font>", "[/color]" => "</font>", "[p]" => "<p>", "[/p]" => "</p>",

                    "[co.de]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>", "

[/code]" => "</p>","
" => "<p style=\"background: #E2E2E2; border: 1px solid #99b3b4; padding: 6px;\"><span style=\"font: bold 10px Courier New;\"></span>", "
" => "</p>" );

                // BBCode array including their replacement.

                $this->vbbcodes =

                    array( "/\/Ui" => "<font size=\"*\">", "/\[face=(.+)\]/U" => "<font face=\"*\">", "/\/Ui" => "<font color=\"*\">", "/\[img\](.+)\[\/img\]/Ui" => "<img src=\"*\" />",

                    "/\[email\](.+)\[\/email\]/Ui" => "<a href=\"mailto:*\">*</a>", "/\[url\](.+)\[\/url\]/Ui" => "<a href=http://\*\>*</a>", "/\(.+)\[\/email\]/Ui" => "<a href=\"mailto:*\">~</a>",

                    "/\(.+)\[\/url\]/Ui" => "<a href=\"*\">~</a>" );

                // Variable BBCode array including their replacement and variable position(s).

                break;

            case 1: // In the case of security being one.

                $this->bbcodes =

                    array( "" => "<i>", "" => "</i>", "" => "<b>", "" => "</b>", "" => "<u>", "" => "</u>", "" => "<del>", "" => "</del>", "[move]" => "<marquee>", "[/move]" => "</marquee>",

                    "

" => "</center>", "" => "<hr />", "

" => "</table>", "" => "</tr>", "" => "<td>",

                    "

" => "</td>", "" => "<sub>", "" => "</sub>", "" => "<sup>", "" => "</sup>", "" => "<tt>", "" => "</tt>", "

" => "</ul>", "[*]" => "<li>",

                    "" => "</li>", "[c.ode]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>",

                    "[/code]" => "</p>" ,"[c.ode]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>", "[/code]" => "</p>");

                // BBCode array including their replacement.

                break;

        }

    }

    function bbcode_formation($mssg) {

$mssg = htmlentities($mssg);

 

    $formats = array(

                      '/\

(.*?)\[\/quote\]/is',

                      );

      $replacement = array(

                      '<div class="quote_title">$1</div><br /><div class="quote">$2</div>',

                      );

 

$mssg = preg_replace($formats, $replacement, $mssg);

return $mssg;

}

    function parseEmoticons($noBBCode=0) { // noBBCode variable defaults to 0. If set to one the parser will not parse be able to parse BBCode.

        if(!$this->selection) { // Check if the user has set the selection.

            $this->debug .= "You must set a value for the selection before parsing! "; // Set the Debug variable if not.

        }else{

            $error = 0; // Default to no errors.

            if($this->parsed) { // If something has already been parsed.

                $selection = str_replace("\n", '', $this->parsed); // Set the parsed value in order to not reset the already parsed selection.

            }elseif($noBBCode==1) { // If nothing has been parsed and the noBBCode variable has been set to one.

                $selection = str_replace("\n", '', $this->selection); // Set the selection value to variable selection.

                $error = 2; // Set the error variable to 2 so that it will not look for [co.de] tags.

            }else{ // If all else fails.

                $this->debug .= "You must parse BBCode first or set the noBBCode variable to 1(setting this variable will not allow bbcode to be parsed)! "; // Set the Debug variable if it gets here.

                $error = 1; // Set the error variable so the parser doesn't run.

            }

            if($error==0 or $error==2) {

                if($error==0) { // Only search if there has been parsing.

                    unset($matches);

                    preg_match_all('/\<p style="background: #BBBBBB; border: 1px solid #555555; padding: 6px;"\>.+\<\/p\>/Uim', $selection, $matches); // Finds all code selections.

                    $i = 0; // Set the variable to the default of 0.

                    while(isset($matches[0][$i])) { // Check for match from preg_match.

                        $selection = str_ireplace($matches[0][$i], "[c.ode$i]", $selection); // Replace for non-emoticon section.

                        $i++; // Add one to the variable to loop.

                    }

                }

                foreach($this->emoticons as $key => $value) { // For each emoticon set the key and value.

                    $v = str_replace(" ", "", $value); // Remove all spaces from value but not replacing the value variable.

                    $v = "<img src=\"" . $this->path2emoticon . strtolower($v) . $this->imgext . "\" alt=\"$value\" />"; // Set the image replacement up.

                    $selection = str_ireplace($key, $v, $selection); // Replace the key with the set up image replacement.

                }

                if($error==0) { // Only search if there has been parsing.

                    while($i>0) { // Reloop through matches.

                        $i--; // Remove one from the variable to loop.

                        $selection = str_ireplace("

 

and called it in my messages by

 

<?php

   $message=$gettopic3['post'];

   $message= BBCode($message);

   echo $message;?>

Link to comment
Share on other sites

Whoops, made a mistake in the code. Try this, without your entire class just the function alone:

 


function bbcode_formation ($mssg) {
    $mssg= htmlentities($mssg);

    $formats = array(
                '/\[quote](.*?)\[\/quote\]/is',
                '/\[quote=(.*?)\](.*?)\[\/quote\]/is',
                );

    $replace_formats = array(
	    '<div class="qoute_header">Quote:</div><div class="quote_body">$1</div>',
	    '<div class="qoute_header">$1 Wrote:</div><div class="quote_body">$2</div>',
                );

    $mssg = preg_replace ($formats, $replace_formats, $mssg);
    return $mssg;
} 

 

Link to comment
Share on other sites

cant get an output... i tried

 

<?php
$mssg= '[qu ote=jp] my quote [/qu ote]';
   $mssg= bbcode_formation ($mssg);

function bbcode_formation ($mssg) {
    $mssg= htmlentities($mssg);

    $formats = array(
                '/\[quote](.*?)\[\/quote\]/is',
                '/\[quote=(.*?)\](.*?)\[\/quote\]/is',
                );

    $replace_formats = array(
    '<div class="qoute_header">Quote:</div><div class="quote_body">$1</div>',
    '<div class="qoute_header">$1 Wrote:</div><div class="quote_body">$2</div>',
                );

    $mssg = preg_replace ($formats, $replace_formats, $mssg);
    return $mssg;
} 
?>

Link to comment
Share on other sites

Don't space the word quote, and you have to echo mssg like below:

<?php
$mssg= '[quote=jp] my quote [/quote]';
   $mssg= bbcode_formation($mssg);
   echo "$mssg";

function bbcode_formation ($mssg) {
    $mssg= htmlentities($mssg);

    $formats = array(
                '/\[quote](.*?)\[\/quote\]/is',
                '/\[quote=(.*?)\](.*?)\[\/quote\]/is',
                );

    $replace_formats = array(
    '<div class="qoute_header">Quote:</div><div class="quote_body">$1</div>',
    '<div class="qoute_header">$1 Wrote:</div><div class="quote_body">$2</div>',
                );

    $mssg = preg_replace ($formats, $replace_formats, $mssg);
    return $mssg;
} 
?>

Link to comment
Share on other sites

Ok so how would i add this fucntion to my exisitng code?

 

<?php protected function selectCodes($security=0) { // Security defaults to 0. Set to 1 for non-variable bbcodes only.
	switch ($security) { // Switch between 0 and 1.
		default: // In the case of security being anything but one. Defaulting to zero.
		case 0: // In the case of security being zero.
			$this->bbcodes =
				array( "[i]" => "<i>", "[/i]" => "</i>",  "[b]" => "<b>", "[/b]" => "</b>", "[u]" => "<u>", "[/u]" => "</u>", "[s]" => "<del>", "[/s]" => "</del>", "[move]" => "<marquee>", "[/move]" => "</marquee>",
				"
[center]" => "<center>", "[/center]
" => "</center>", "[hr]" => "<hr />", "[table]" => "<table>", "[/table]" => "</table>", "[tr]" => "<tr>", "[/tr]" => "</tr>", "[td]" => "<td>",
				"[/td]" => "</td>", "[sub]" => "<sub>", "[/sub]" => "</sub>", "[sup]" => "<sup>", "[/sup]" => "</sup>", "[tt]" => "<tt>", "[/tt]" => "</tt>", "[list]" => "<ul>", "[/list]" => "</ul>", "[*]" => "<li>",
				"" => "</li>", "[/size]" => "</font>", "[/face]" => "</font>", "[/color]" => "</font>", "[p]" => "<p>", "[/p]" => "</p>",
				"[code]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>", "[/c.ode]" => "</p>","[quote]" => "<p style=\"background: #E2E2E2; border: 1px solid #99b3b4; padding: 6px;\"><span style=\"font: bold 10px Courier New;\"></span>", "[/quote]" => "</p>" );
			// BBCode array including their replacement.
			$this->vbbcodes = 
				array( "/\[size=(.+)\]/Ui" => "<font size=\"*\">", "/\[face=(.+)\]/U" => "<font face=\"*\">", "/\[color=(.+)\]/Ui" => "<font color=\"*\">", "/\[img\](.+)\[\/img\]/Ui" => "<img src=\"*\" />",
				"/\[email\](.+)\[\/email\]/Ui" => "<a href=\"mailto:*\">*</a>", "/\[url\](.+)\[\/url\]/Ui" => "<a href=http://\*\>*</a>", "/\[email=(.+)\](.+)\[\/email\]/Ui" => "<a href=\"mailto:*\">~</a>",
				"/\[url=(.+)\](.+)\[\/url\]/Ui" => "<a href=\"*\">~</a>" );
			// Variable BBCode array including their replacement and variable position(s).
			break;
		case 1: // In the case of security being one.
			$this->bbcodes =
				array( "[i]" => "<i>", "[/i]" => "</i>", "[b]" => "<b>", "[/b]" => "</b>", "[u]" => "<u>", "[/u]" => "</u>", "[s]" => "<del>", "[/s]" => "</del>", "[move]" => "<marquee>", "[/move]" => "</marquee>",
				"
[center]" => "<center>", "[/center]
" => "</center>", "[hr]" => "<hr />", "[table][tr][td]" => "<table>", "" => "</table>", "[table][tr][td]" => "<tr>", "[/td][/tr][/table]" => "</tr>", "[table][tr][td]" => "<td>",
				"[/td][/tr][/table]" => "</td>", "[sub]" => "<sub>", "[/sub]" => "</sub>", "[sup]" => "<sup>", "[/sup]" => "</sup>", "[tt]" => "<tt>", "[/tt]" => "</tt>", "[list]" => "<ul>", "[/list]" => "</ul>", "[list][*]" => "<li>",
				"[/list]" => "</li>", "[/td][/tr][/table][code]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>",
				"[/c.ode]" => "</p>" ,"[c.ode]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>", "[/c.ode]" => "</p>");
			// BBCode array including their replacement.
			break; ?>

Link to comment
Share on other sites

Here, I added it for you:

 

<?php protected function selectCodes($security=0) { // Security defaults to 0. Set to 1 for non-variable bbcodes only.
      switch ($security) { // Switch between 0 and 1.
         default: // In the case of security being anything but one. Defaulting to zero.
         case 0: // In the case of security being zero.
            $this->bbcodes =
               array( "[i]" => "<i>", "[/i]" => "</i>",  "[b]" => "<b>", "[/b]" => "</b>", "[u]" => "<u>", "[/u]" => "</u>", "[s]" => "<del>", "[/s]" => "</del>", "[move]" => "<marquee>", "[/move]" => "</marquee>",
               "
[center]" => "<center>", "[/center]
" => "</center>", "[hr]" => "<hr />", "[table][tr][td]" => "<table>", "" => "</table>", "[table][tr][td]" => "<tr>", "[/td][/tr][/table]" => "</tr>", "[table][tr][td]" => "<td>",
               "[/td][/tr][/table]" => "</td>", "[sub]" => "<sub>", "[/sub]" => "</sub>", "[sup]" => "<sup>", "[/sup]" => "</sup>", "[tt]" => "<tt>", "[/tt]" => "</tt>", "[list]" => "<ul>", "[/list]" => "</ul>", "[list][*]" => "<li>",
               "[/list]" => "</li>", "[/size]" => "</font>", "[/face]" => "</font>", "[/color]" => "</font>", "[p]" => "<p>", "[/p]" => "</p>",
               "[/td][/tr][/table][code]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>", "[/c.ode]" => "</p>","[quote]" => "<p style=\"background: #E2E2E2; border: 1px solid #99b3b4; padding: 6px;\"><span style=\"font: bold 10px Courier New;\"></span>", "[/quote]" => "</p>" );
            // BBCode array including their replacement.
            $this->vbbcodes = 
               array( "/\[size=(.+)\]/Ui" => "<font size=\"*\">", "/\[face=(.+)\]/U" => "<font face=\"*\">", "/\[color=(.+)\]/Ui" => "<font color=\"*\">", "/\[img\](.+)\[\/img\]/Ui" => "<img src=\"*\" />",
               "/\[email\](.+)\[\/email\]/Ui" => "<a href=\"mailto:*\">*</a>", "/\[url\](.+)\[\/url\]/Ui" => "<a href=http://\*\>*</a>", "/\[email=(.+)\](.+)\[\/email\]/Ui" => "<a href=\"mailto:*\">~</a>",
               "/\[url=(.+)\](.+)\[\/url\]/Ui" => "<a href=\"*\">~</a>", "/\[quote](.+)\[\/quote\]/is" => "<div class=\"qoute_header\">Quote:</div><div class=\"quote_body\">*</div>", "/\[quote=*\]*\[\/quote\]/is" => "<div class=\"qoute_header\">* Wrote:</div><div class=\"quote_body\">*</div>" );
            // Variable BBCode array including their replacement and variable position(s).
            break;
         case 1: // In the case of security being one.
            $this->bbcodes =
               array( "[i]" => "<i>", "[/i]" => "</i>", "[b]" => "<b>", "[/b]" => "</b>", "[u]" => "<u>", "[/u]" => "</u>", "[s]" => "<del>", "[/s]" => "</del>", "[move]" => "<marquee>", "[/move]" => "</marquee>",
               "
[center]" => "<center>", "[/center]
" => "</center>", "[hr]" => "<hr />", "[table][tr][td]" => "<table>", "" => "</table>", "[table][tr][td]" => "<tr>", "[/td][/tr][/table]" => "</tr>", "[table][tr][td]" => "<td>",
               "[/td][/tr][/table]" => "</td>", "[sub]" => "<sub>", "[/sub]" => "</sub>", "[sup]" => "<sup>", "[/sup]" => "</sup>", "[tt]" => "<tt>", "[/tt]" => "</tt>", "[list]" => "<ul>", "[/list]" => "</ul>", "[list][*]" => "<li>",
               "[/list]" => "</li>", "[/td][/tr][/table][code]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>",
               "[/c.ode]" => "</p>" ,"[c.ode]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>", "[/c.ode]" => "</p>");
            // BBCode array including their replacement.
            break; ?>

[/code]

Link to comment
Share on other sites

here is the full code

 

<?php
class BBCode {
protected $bbcodes; // Store array of BBCodes
protected $vbbcodes; // Store array of Variable BBCodes
var $debug = ''; // Store any errors
var $selection = ''; // Store the selection to be parsed first
var $parsed = ''; // Store the parsed selection.
var $path2emoticon = 'http://www.runningprofiles.com/emoticons/'; // Set the path to the emoticon images.
var $imgext = '.gif'; // Set this to the ext of the images
public $emoticons = 
	array( '' => 'Roll Eyes', '' => 'Smiley', '' => 'Wink', '' => 'Cheesy', '' => 'Grin', '' => 'Angry',
	'' => 'Sad', '' => 'Shocked', '' => 'Cool', '???' => 'Huh', '' => 'Tongue', ':-[' => 'Embarrassed', 
	':-X' => 'Lips Sealed', ':-\\' => 'Undecided', '' => 'Kiss', ':*(' => 'Cry' ); 
	// All emoticons. Spaces and caps will be removed for image names.

function parseCode($security=0) { // Security defaults to 0. Set to 1 for non-variable bbcodes only.
	if(!$this->selection) { // Check if the user has set the selection.
		$this->debug .= "You must set a value for the selection before parsing! "; // Set the Debug variable if not.
	}else{
		if($this->parsed) { // Check if text has already been parsed.
			$this->debug .= "You must run the code parser before the emoticon parser! "; // Set the Debug variable if so.
		}else{
			$selection = str_replace("\n", '', $this->selection); // Set selection variable for inside function only.
			$selection2 = htmlentities(str_replace("\n", '', $this->selection)); // Remove html entities for security.
			$this->selectCodes($security); // Select codes depending on security.
			#### Start [code] Section ###
			preg_match_all("/\[code\].+\[\/code\]/Ui", $selection2, $matches); // Check for [code] tags. Set the matches array.
			$i = 0; // Set the variable to the default of 0.
			while(isset($matches[0][$i])) { // Check for match from preg_match.
				$selection = str_ireplace(html_entity_decode($matches[0][$i]), "[code$i]", $selection); // Decode and replace for strip tags.
				$i++; // Add one to the variable to loop.
			}
			$selection = strip_tags($selection); // Strip tags from the selection.
			while($i>0) { // Reloop through matches.
				$i--; // Remove one from the variable to loop.
				$m = html_entity_decode($matches[0][$i]); // Decode the match for accurate removal.
				$m = str_ireplace("[code]", "", $m); // Remove [code] tag.
				$m = str_ireplace("

", "", $m); // Remove [/code] tag.

$m = highlight_string($m,true); // Highlight string and encode.

$selection = str_ireplace("

[code$i]", "
" . $m . "

", $selection); // Add highlighted code back with tags for later parsing.

}

#### End

 Section ####
			### Start BBCode Section ###
			foreach ($this->bbcodes as $key => $value) { // Loop through bbcodes.
				$selection = str_ireplace($key, $value, $selection); // Replace the $key value(bbcode) with the $value value(html code).
			}
			#### End BBCode Section ###
			### Start Var. BBCode Sec. ##
			if($security==0) { // Only loop through if security allows it.
				foreach ($this->vbbcodes as $key => $value) { // Loop through variable bbcodes.
					unset($matches); // Unset matches set in earlier code.
					$i = 0; // Set the variable to the default of 0.
					preg_match_all($key, $selection, $matches); // Find all instances of the variable bbcode set them to matches.
					// Preg Matching also stores the "variables" inside the matches var. with the matches.
					while(isset($matches[0][$i])) { // Check if there are any instances.
						$v = str_replace("*", $matches[1][$i], $value); // Replace the asterisk with the variable value.
						if(isset($matches[2][$i])) { // Check for more than one variable.
							$v = str_replace("~", $matches[2][$i], $v); // Replace the ~ with the second variable value.
						}
						$selection = str_replace($matches[0][$i], $v, $selection); // Replace the match with the accumulated variable.
						$i++; // Add one to the variable to loop.
					}
				}
			}
			### End Var. BBCode Sec. ##
			$this->parsed = $selection; // Insert the accumulated parsed selection into the parsed variable as to keep selection original.
			unset($selection); // Remove all value from private variable selection.
		}
	}
}

protected function selectCodes($security=0) { // Security defaults to 0. Set to 1 for non-variable bbcodes only.
	switch ($security) { // Switch between 0 and 1.
		default: // In the case of security being anything but one. Defaulting to zero.
		case 0: // In the case of security being zero.
			$this->bbcodes =
				array( "[i]" => "<i>", "[/i]" => "</i>",  "[b]" => "<b>", "[/b]" => "</b>", "[u]" => "<u>", "[/u]" => "</u>", "[s]" => "<del>", "[/s]" => "</del>", "[move]" => "<marquee>", "[/move]" => "</marquee>",
				"
[center]" => "<center>", "[/center]
" => "</center>", "[hr]" => "<hr />", "[table]" => "<table>", "[/table]" => "</table>", "[tr]" => "<tr>", "[/tr]" => "</tr>", "[td]" => "<td>",
				"[/td]" => "</td>", "[sub]" => "<sub>", "[/sub]" => "</sub>", "[sup]" => "<sup>", "[/sup]" => "</sup>", "[tt]" => "<tt>", "[/tt]" => "</tt>", "[list]" => "<ul>", "[/list]" => "</ul>", "[*]" => "<li>",
				"" => "</li>", "[/size]" => "</font>", "[/face]" => "</font>", "[/color]" => "</font>", "[p]" => "<p>", "[/p]" => "</p>",
				"[code]" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>", "

" => "</p>","

" => "<p style=\"background: #E2E2E2; border: 1px solid #99b3b4; padding: 6px;\"><span style=\"font: bold 10px Courier New;\"></span>", "
" => "</p>" );

// BBCode array including their replacement.

$this->vbbcodes =

array( "/\/Ui" => "<font size=\"*\">", "/\[face=(.+)\]/U" => "<font face=\"*\">", "/\/Ui" => "<font color=\"*\">", "/\[img\](.+)\[\/img\]/Ui" => "<img src=\"*\" />",

"/\[email\](.+)\[\/email\]/Ui" => "<a href=\"mailto:*\">*</a>", "/\[url\](.+)\[\/url\]/Ui" => "<a href=http://\*\>*</a>", "/\(.+)\[\/email\]/Ui" => "<a href=\"mailto:*\">~</a>",

"/\(.+)\[\/url\]/Ui" => "<a href=\"*\">~</a>, "/\

(.+)\[\/quote\]/is" => "<div class=\"qoute_header\">Quote:</div><div class=\"quote_body\">*</div>", "/\
*\[\/quote\]/is" => "<div class=\"qoute_header\">* Wrote:</div><div class=\"quote_body\">*</div>" );

// Variable BBCode array including their replacement and variable position(s).

break;

case 1: // In the case of security being one.

$this->bbcodes =

array( "" => "<i>", "" => "</i>", "" => "<b>", "" => "</b>", "" => "<u>", "" => "</u>", "" => "<del>", "" => "</del>", "[move]" => "<marquee>", "[/move]" => "</marquee>",

"

" => "</center>", "" => "<hr />", "

" => "</table>", "" => "<tr>", "" => "</tr>", "" => "<td>",

"

" => "</td>", "" => "<sub>", "" => "</sub>", "" => "<sup>", "" => "</sup>", "" => "<tt>", "" => "</tt>", "

" => "</ul>", "[*]" => "<li>",

"" => "</li>", "

" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>",
				"

" => "</p>" ,"

" => "<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"><span style=\"font: bold 10px Courier New;\">   CODE :</span><br/>", "

" => "</p>");

// BBCode array including their replacement.

break;

}

}

function parseEmoticons($noBBCode=0) { // noBBCode variable defaults to 0. If set to one the parser will not parse be able to parse BBCode.

if(!$this->selection) { // Check if the user has set the selection.

$this->debug .= "You must set a value for the selection before parsing! "; // Set the Debug variable if not.

}else{

$error = 0; // Default to no errors.

if($this->parsed) { // If something has already been parsed.

$selection = str_replace("\n", '', $this->parsed); // Set the parsed value in order to not reset the already parsed selection.

}elseif($noBBCode==1) { // If nothing has been parsed and the noBBCode variable has been set to one.

$selection = str_replace("\n", '', $this->selection); // Set the selection value to variable selection.

$error = 2; // Set the error variable to 2 so that it will not look for

 tags.
		}else{ // If all else fails.
			$this->debug .= "You must parse BBCode first or set the noBBCode variable to 1(setting this variable will not allow bbcode to be parsed)! "; // Set the Debug variable if it gets here.
			$error = 1; // Set the error variable so the parser doesn't run.
		}
		if($error==0 or $error==2) {
			if($error==0) { // Only search if there has been parsing.
				unset($matches);
				preg_match_all('/\<p style="background: #BBBBBB; border: 1px solid #555555; padding: 6px;"\>.+\<\/p\>/Uim', $selection, $matches); // Finds all code selections.
				$i = 0; // Set the variable to the default of 0.
				while(isset($matches[0][$i])) { // Check for match from preg_match.
					$selection = str_ireplace($matches[0][$i], "[code$i]", $selection); // Replace for non-emoticon section.
					$i++; // Add one to the variable to loop.
				}
			}
			foreach($this->emoticons as $key => $value) { // For each emoticon set the key and value.
				$v = str_replace(" ", "", $value); // Remove all spaces from value but not replacing the value variable.
				$v = "<img src=\"" . $this->path2emoticon . strtolower($v) . $this->imgext . "\" alt=\"$value\" />"; // Set the image replacement up.
				$selection = str_ireplace($key, $v, $selection); // Replace the key with the set up image replacement.
			}
			if($error==0) { // Only search if there has been parsing.
				while($i>0) { // Reloop through matches.
					$i--; // Remove one from the variable to loop.
					$selection = str_ireplace("[code$i]", $matches[0][$i], $selection); // Add the codes back for final display.
				}
			}
			$this->parsed = $selection; // Insert the accumulated parsed selection into the parsed variable as to keep selection original.
			unset($selection); // Remove all value from private variable selection.
		}
	}
}
}
?>

[/code]

Link to comment
Share on other sites

ok im trying this

 

"/\[quote](.+)\[\/quote\]/is" => "<div class=\"quote_header\">Quote:</div><div class=\"quote_body\">*</div>", "/\[quote=(.*)\](.*)\[\/quote\]/is" => "<p style=\"background: #e4ebeb; border: 1px solid #555555; padding: 6px;\"><div class=\"quote_header\"><span style=\"color:#0000FF; font:'Courier New', Courier, mono; font-size:10px"> "Quote by</span><strong> *</strong> :</div>" );

 

and im getting no output :S

Link to comment
Share on other sites

ok i have messed around with it to come up with my final error before its working...

 

"/\[quote=(.*)\](.*)\[\/quote\]/is" => "<div style=\"background: #e4ebeb; border: 1px solid #555555; padding: 6px;\">
<div style=\"font-size:10px; color:#043050;\">Quote by * :</div>
<div class=\"quote_body\">*</div></div>

 

that is the final code... but its echoing out here = <div class=\"quote_body\">*</div> the users name again rather then there message

Link to comment
Share on other sites

Try this:

 

"/\[quote=(.*?)\](.*?)\[\/quote\]/is" => "<div style=\"background: #e4ebeb; border: 1px solid #555555; padding: 6px;\">
<div style=\"font-size:10px; color:#043050;\">Quote by $1 :</div>
<div class=\"quote_body\">$2</div></div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.