Howdy... 😉

I have several regular expressions questions... First of all, I am a Flash developer... I do not have good grasp of the PHP or regular expressions, but I am currently working on the bbCode tag for the phpBB software...
What I want to do is to create a custom bbCode that will read the Flash ActionScript and then generate the output with the predefined color set to display the reserved words and comments and such in different colors... Basically the [ PHP] tag for the Flash ActionScript it is...

  1. I want the whole line to be colored in the color that is defined for the comment line...
    This is how I see at the moment, (No actual BOLD face used in the example, but I have used it to show you where it happens...)

    // method. In doing so it increases the speed of

    and this is how it should be...

    // method. In doing so it increases the speed of

  2. Some reserved words are not really detected...
    For example, I have 'in' and 'int' as reserved words, yet the script just detects 'in' onliy in this case like this...

    Object.minorVersion = int(Object.version[2]);

  3. I have defined my reserved words like this...

       $as['reserved'] = array(                    
    ' add', ' and', ' break', ' call', ' case', ' continue', ' default', ' delete', ' do', ' else', ' elseif', ' eq', ' false', ' for', ' function', ' if', ' in', ' int', ' instanceof', ' new', ' newline', ' not', ' null', ' on', ' or', ' onClipEvent', ' return', ' set', ' super', ' switch', ' this', ' true', ' typeof', ' undefined', ' var', ' void', ' while', ' with' );

    Here for example, ' in'... As you can see, I have added ' '(space) in front of the keyword... If I omit it, I do get all the instances of 'in' to be displayed in green color like this...

    built-[COLOR=green][b]in[/b][/color] 
    [COLOR=green][b]in[/b][/color]creases 
    conta[COLOR=green][b]in[/b][/color] 
    plug[COLOR=green][b]in[/b][/color] 
    m[COLOR=green][b]in[/b][/color]orVersion

    You get the idea... So, my question is how to resolve this issue???

  1. I don't know why, but some reserved words are not really checked at all...

    For example, this line displays...

    this.firstChild.removeNode();
    var treePtr = this;

    but it actually is missing the first occurance of 'this' which should be displayed like this...

    this.firstChild.removeNode();
    var treePtr = this;

  1. This I have no idea yet, but I'd like to set a set of functions to be displayed in, say, red color... Those reserved words are sorta done, but I have no idea how to add additional words array to be checked...

This is the function that I have got at the moment...

/**
 * 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', 'c ontinue',
	' default', ' delete', ' do',
	' else', ' eq',
	' false', ' for', ' function',
	' if', ' in', ' int',
	' instanceof',
	' new', ' newline', ' not', ' null',
	' on', ' or', ' onClipEvent',
	' return',
	' set', ' super', ' switch',
	' this', ' true', ' typeof',
	' undefined',
	' var', ' void',
	' while', ' with'
);

$str = preg_replace('/([\"])(.*?)([\"])/si', '<font color="' . $color['string'] . '">\\1\\2\\3</font>', $str);

for ($x = 0; $x < count($as['reserved']); $x++) {
	$str = str_replace($as['reserved'][$x], '<font color="' . $color['reserved'] . '">' . $as['reserved'][$x] . '</font>', $str);
}

$str = preg_replace('[\/\*]', '<font color="' . $color['comment'] . '">\\1\\2\\3/*', $str);
$str = preg_replace('[\*\/]', '*/</font>', $str);
$str = preg_replace('/(\/\/)(.*?)([\n])/si', '<font color="' . $color['comment'] . '">\\1\\2\\3\\4</font>', $str);

$str = str_replace("\n", '<br />', $str);
$str = '<font color="' . $color['default'] . '">' . $str . '</font>';

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("&lt;", "&gt;");

$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);

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 "&nbsp; " so non-tabbed code indents without making huge long lines.
	$after_replace = str_replace("  ", "&nbsp; ", $after_replace);
	// now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
	$after_replace = str_replace("  ", " &nbsp;", $after_replace);

	// Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
	$after_replace = str_replace("\t", "&nbsp; &nbsp; &nbsp; ", $after_replace);

	$str_to_match = "[as:1:$uid]" . $before_replace . "[/as:1:$uid]";

	$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:$uid]", $code_end_html, $text);

return $text;

} // bbencode_second_pass_as()

To sum up, I think this all comes down to my lack of regular expression... It's been too long since I have used it so I hardly remember it... Anybody know any good online material for the RE???

The current script is implemented into the my test board which can be found at http://forum.flashvacuum.com and the specific thread that shows the [AS] tag example is http://forum.flashvacuum.com/viewtopic.php?t=201
You can use 'test/test' to login and test the script if you want to...

Any help is very appreciated... Thanks for your time to read this...

Jason

    I Think I can answer some of your problems. Its not regexp thats the problem. It how php interprets strings.

    1., 2., 3., and 4 are actually the same thing. I shall try to explain. When php matches a string it matches exactly what is there. So in the case of the line

    this.firstChild.removeNode();
    var treePtr = this;

    The highlighting with the comment can be solved by not running the highlight on anything that has a comment in it.

    It is correct to only highlight the second occurance of 'this' the first one doesn't have a space before it so you will need to add 'this.' to your list of reserved words. Simular is true for the occurances of 'in' and 'do'. The words with a prefixed space do exist so thats what gets matched. You will need to change those entries to ' in '. (Space before and after) this should also solve the problem of not spotting 'int' as a keyword.

      Thank you very much for the reply, khaine... 🙂

      I do understand why you have said that I should define all the occurances of 'this' and 'this.' to get the right output, but there is one thing I do not understand...

      I have read that I can use '' to specify the match that occurs at the beginning of the line... Isn't there a way I can specify that sort of thing for each word??? For example, if the word 'this' appears in the beginning of the word, then do whatever is necessary and such...

      For now, I have given the spaces in the beginning and the end of each reserved words, and it kinda does the job, but am I supposed to specify all the occurances like this???
      ' this ', ' this.', ' this;', ' this)' and so on???
      Wouldn't this slow the process in the long run???

      The highlighting with the comment can be solved by not running the highlight on anything that has a comment in it.

      Can you give me some more hint on it??? I think that's what should be done, but I don't know where to start... 🙁

      Thank you for your time... 😉

        If I understand your code correctly this bit

        
        $str = preg_replace('[/*]', '<font color="' . $color['comment'] . '">\1\2\3/*', $str); 
            $str = preg_replace('[*/]', '*/</font>', $str); 
            $str = preg_replace('/(//)(.*?)([\n])/si', '<font color="' . $color['comment'] . '">\1\2\3\4</font>', $str);
        
        

        deals with the highlighting of a comment. You could move this to the start of the code, Deal with that first then not run the rest if this bit has been invoked. i.e.

        
        function as_highlight_string($str) 
        { 
            $color['comment'] = '#FF9900'; 
            $color['default'] = '#000000'; 
            $color['reserved'] = '#009900'; 
            $color['string'] = '#0000FF'; 
        
            $str = preg_replace('[/*]', '<font color="' . $color['comment'] . '">\1\2\3/*', $str); 
        $str = preg_replace('[*/]', '*/</font>', $str); 
        $str = preg_replace('/(//)(.*?)([\n])/si', '<font color="' . $color['comment'] . '">\1\2\3\4</font>', $str); 
        
        $as['reserved'] = array( 
            ' add', ' and', 
            ' break', 
            ' call', ' case', 'c ontinue', 
            ' default', ' delete', ' do', 
            ' else', ' eq', 
            ' false', ' for', ' function', 
            ' if', ' in', ' int', 
            ' instanceof', 
            ' new', ' newline', ' not', ' null', 
            ' on', ' or', ' onClipEvent', 
            ' return', 
            ' set', ' super', ' switch', 
            ' this', ' true', ' typeof', 
            ' undefined', 
            ' var', ' void', 
            ' while', ' with' 
        ); 
        
        $str = preg_replace('/([\"])(.*?)([\"])/si', '<font color="' . $color['string'] . '">\1\2\3</font>', $str); 
        
        if ( !strstr($str, $color['comment'] ) )
        {
            for ($x = 0; $x < count($as['reserved']); $x++) { 
                $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>'; 
        
        return($str); 
        } // as_highlight_string() 
        
        

        All this does is looks for the comment color on the current line. This will only have a problem if the comment color is use for any other purpose. So if you set the default color to be white and the comment color to be white it won't highlight the reserved words.

        Mark.

          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("&lt;", "&gt;");
          
          $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 "&nbsp; " so non-tabbed code indents without making huge long lines.
          	$after_replace = str_replace("  ", "&nbsp; ", $after_replace);
          	// now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
          	$after_replace = str_replace("  ", " &nbsp;", $after_replace);
          
          	// Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
          	$after_replace = str_replace("\t", "&nbsp; &nbsp; &nbsp; ", $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???

            It could be an idea to look at the html itself. I guess that it will look like

            
            <font color="#00000">// try the background at #006699, #0066BB, <font color="#FFFFFF">and</font> #000000.</font>
            
            

            This is what I would expect anyway. The color codes are probably different though. What you are going to need to do is not run the color reserved words bit when a comment has been colored.

            I tried to run your code but just got a screen full of warnings and no output at all

            Warning: Unknown modifier '/' in c:\my documents\htdocs\test.php on line 56

            Warning: Compilation failed: nothing to repeat at offset 0 in c:\my documents\htdocs\test.php on line 60

            What versions are you running?

            Mark.

              Howdy... 😉

              I do not understand why you were getting that errors... 🙁

              This file is running on PHP 4.2.2 over Apache 1.3.22, and it worked just fine on my localhost with IIS 5.0 and PHP 4.2.3...

              http://cyanblue.flashvacuum.com/tmp/preg1.php
              http://cyanblue.flashvacuum.com/tmp/preg1.phps

              That above PHP file output goes like this and it looks fine to me... Is it???

              <font color="#000000">
              	<font color="#FF9900">// try the background at #006699, #0066BB,
              		<font color="#009900"> and </font>
              		#000000.<br />
              	<font color="#FF9900">/*
              		<font color="#009900">this.</font>
              		aboutBtn_mc.onRollOver = function() {<br />&nbsp; &nbsp; &nbsp; 
              		<font color="#009900">this.</font>
              		aboutBtn_mc.gotoAndStop(
              		<font color="#0000FF">"_over"</font>
              		);<br />&nbsp; &nbsp; &nbsp; about(); 
              		//
              		<font color="#009900"> call </font>
              		the about() function<br />} // end aboutBtn_mc.onRollOver<br />*/</font>
              		<br />Line 1<br /> Line 2<br />&nbsp; Line 3
              	</font>
              	<br />
              </font>

                There must have been a fault when I copied and pasted your code from the forum. When i ran the phps from your site it worked fine.

                I got

                <font color="#000000">
                <font color="#FF9900">// try the background at #006699, #0066BB,
                <font color="#009900"> and </font>
                #000000.<br />
                <font color="#FF9900">/
                <font color="#009900">this.</font>
                aboutBtn_mc.onRollOver = function() {<br />

                <font color="#009900">this.</font>
                aboutBtn_mc.gotoAndStop(
                <font color="#0000FF">"_over"</font>
                );<br /> about();
                //<font color="#009900"> call </font>
                the about() function<br />} // end aboutBtn_mc.onRollOver<br />
                /</font>
                <br />Line 1<br /> Line 2<br /> Line 3
                </font>
                <br />
                </font>

                It looks fine must have been human error on my part.

                It still highlights keywords in the comment though maybe you should try

                
                <?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);
                
                    if ( !strstr($str, $color['comment']) )
                    {
                //	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("&lt;", "&gt;");
                
                $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 "&nbsp; " so non-tabbed code indents without making huge long lines.
                	$after_replace = str_replace("  ", "&nbsp; ", $after_replace);
                	// now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
                	$after_replace = str_replace("  ", " &nbsp;", $after_replace);
                
                	// Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
                	$after_replace = str_replace("\t", "&nbsp; &nbsp; &nbsp; ", $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()
                
                ?>
                
                

                the only bit I have changed is to add the strstr comparison before the loop to highlight the string.

                Mark.

                  strstr() function??? I wouldn't think about that sort of function with my limited knowledge in PHP... 😃

                  Thank you very much... 😉

                  I still got a long way to go, but this should get me going...

                  Can you tell me what this part is if you don't mind??? I have read the PHP manual, but I am not quite getting them...

                  What is the meaning of the '\1\2\3\4' in that preg_replace() function line and the '/si' part in the RegExp???

                    Ah... That's pretty good reference... Thank you very much... I'll take a look at it... 🙂

                      Write a Reply...