Writing a text filter... something like Textile only streamline and simpler. About done with the filter proper, but trying to streamline the code.

I wrote this to set font size on the fly:


function _myfilter_filter_fontsize($chr, &$text)    // If chr match here...
{
  if (strstr($text, $chr))                           // Three X as fast with this.
  {
    $text = preg_replace('/
      '.$chr.'([0-7])        # Token and any digit from 0 to 7, 
      (.+)                   # 1 or more characters followed 
      '.$chr.'{1}            # by one token 
      [0-7]{0,1}             # and an optional digit. 
      /x', "<font size=\"$1\">$2</font>", $text);
      $text = str_replace("$chr$chr",            // Double chr escapes.
                           $chr, $text); 
  }
}

If I'm using a ~ as my flag, the syntax would be:

The font is normal ~3THEN BIGGER~ then returns back to normal when I type another ~ OR a ~ and some numeral.

What I'd like to know is how to make the second numeral THE SAME numeral as the first. In other words, is there a syntax for the regex string that allows me to specify the $1 variable as I did in the replacement string?

Curtis

Comments

chx’s picture

syntax is \\1 or \1 depending on whether " or ' used.
--
Read my developer blog on Drupal4hu.

--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.

CLamont’s picture

That did the trick... thanks a lot. Saved me more hours of slogging through manuals, I'm sure.

Curtis