Howdy, khaine... Thanks for the reply... 🙂
I don't know what I did exactly, but this is what I have so far... You can try this script if you want to... 😉
<?php
$text = "[as]";
$text .= "// try the background at #006699, #0066BB, and #000000.\n";
$text .= "/* this.aboutBtn_mc.onRollOver = function() {\n";
$text .= " this.aboutBtn_mc.gotoAndStop(\"_over\");\n";
$text .= " about(); // call the about() function\n";
$text .= "} // end aboutBtn_mc.onRollOver\n";
$text .= "*/\n";
$text .= "Line 1\n";
$text .= " Line 2\n";
$text .= " Line 3\n";
$text .= "[/as]";
$uid = "1";
$bbcode_tpl = "test";
$text = bbencode_second_pass_as($text, $uid, $bbcode_tpl);
/**
* AS MOD
* as_highlight_string($str)
* - All parameters required
* - Returns a string
* Takes a string and color codes it to AS's syntax.
* BEWARE! This CAN and WILL slow down page generation times! At least with large chunks of code.
* NOTE: The order of preg_replace's and str_replace's is key--DO NOT REORDER UNLESS YOU KNOW WHAT YOU'RE DOING
*/
function as_highlight_string($str)
{
$color['comment'] = '#FF9900';
$color['default'] = '#000000';
$color['reserved'] = '#009900';
$color['string'] = '#0000FF';
$as['reserved'] = array(
' add ', ' and ',
' break',
' call ', ' case ', ' continue ',
' default ', ' delete ', ' do ',
' else ', ' eq ',
' false ', ' for ', ' function ',
' if ', ' in ', ' int ', ' instanceof ',
' new ', ' newline ', ' not ', ' null ',
' on ', ' or ', ' onClipEvent ',
' return ',
' set ', ' super ', ' switch ',
'this.', 'this;', ' true ', ' typeof ',
' undefined ',
' var ', ' void ',
' while ', ' with '
);
$str = preg_replace('/([\"])(.*?)([\"])/si', '<font color="' . $color['string'] . '">\\1\\2\\3</font>', $str);
$str = preg_replace('/(\/\/)(.*?)$/si', '<font color="' . $color['comment'] . '">\\1\\2\\3\\4</font>', $str);
// $str = preg_replace('/(\/\/)(.*?)$([\n])/si', '<font color="' . $color['comment'] . '">\\1\\2\\3\\4</font>', $str);
// $str = preg_replace('/([\/\*])(.*?)$([\*\/])/si', '<font color="' . $color['comment'] . '">\\1\\2\\3</font>', $str);
$str = preg_replace('[\/\*]', '<font color="' . $color['comment'] . '">/*\\1\\2\\3', $str);
$str = preg_replace('[\*\/]', '*/</font>', $str);
// for ($z = 0; $z < strlen($str); $z++) {
// print($str[$z] . " ::: " . strlen($str) . "<br />");
// }
for ($x = 0; $x < count($as['reserved']); $x++) {
// echo("::: : " . $x . "<br />");
$str = str_replace($as['reserved'][$x], '<font color="' . $color['reserved'] . '">' . $as['reserved'][$x] . '</font>', $str);
}
$str = str_replace("\n", '<br />', $str);
$str = '<font color="' . $color['default'] . '">' . $str . '</font>';
echo($str);
return($str);
} // as_highlight_string()
/**
* AS MOD
* Does second-pass bbencoding of the [AS] tags. This includes
* running htmlspecialchars() over the text contained between
* any pair of [AS] tags that are at the first level of
* nesting. Tags at the first level of nesting are indicated
* by this format: [as:1:$uid] ... [/as:1:$uid]
* Other tags are in this format: [as:$uid] ... [/as:$uid]
*
* Original code/function by phpBB Group
* Modified by JW Frazier / Fubonis < [email]php@fubonis.com[/email] >
*/
function bbencode_second_pass_as($text, $uid, $bbcode_tpl)
{
global $lang;
$html_entities_match = array("#<#", "#>#");
$html_entities_replace = array("<", ">");
$code_start_html = $bbcode_tpl['as_open'];
$code_end_html = $bbcode_tpl['as_close'];
// First, do all the 1st-level matches. These need an htmlspecialchars() run,
// so they have to be handled differently.
// $match_count = preg_match_all("#\[as:1:$uid\](.*?)\[/as:1:$uid\]#si", $text, $matches);
$match_count = preg_match_all("#\[as\](.*?)\[/as]#si", $text, $matches);
for ($i = 0; $i < $match_count; $i++)
{
$before_replace = $matches[1][$i];
$after_replace = $matches[1][$i];
$after_replace = preg_replace($html_entities_match, $html_entities_replace, $after_replace);
// Replace 2 spaces with " " so non-tabbed code indents without making huge long lines.
$after_replace = str_replace(" ", " ", $after_replace);
// now Replace 2 spaces with " " to catch odd #s of spaces.
$after_replace = str_replace(" ", " ", $after_replace);
// Replace tabs with " " so tabbed code indents sorta right without making huge long lines.
$after_replace = str_replace("\t", " ", $after_replace);
// $str_to_match = "[as:1:$uid]" . $before_replace . "[/as:1:$uid]";
$str_to_match = "[as]" . $before_replace . "[/as]";
$replacement = $code_start_html;
$after_replace = as_highlight_string($after_replace);
$replacement .= $after_replace;
$replacement .= $code_end_html;
$text = str_replace($str_to_match, $replacement, $text);
}
// Now, do all the non-first-level matches. These are simple.
// $text = str_replace("[as:$uid]", $code_start_html, $text);
$text = str_replace("[as]", $code_start_html, $text);
// $text = str_replace("[/as:$uid]", $code_end_html, $text);
$text = str_replace("[/as]", $code_end_html, $text);
return $text;
} // bbencode_second_pass_as()
?>
and the output is still not what I am expecting...
I get orange color strings whenever '//' or '/ ... /' is met, but the reserved words that are within that comment line are still showing up in the green color where they should be displayed in orange colors because they are in the commented line... What am I doing wrong???
// try the background at #006699, #0066BB, and #000000.
// try the background at #006699, #0066BB, and #000000.
and the last three lines should be the default color, yet they are still in orange... 🙁
What is the meaning of the '\1\2\3\4' in that preg_replace() function line and the '/si' part in the RegExp???