[EMAIL PROTECTED] wrote:
All I want to do is capture the keyword (array, break, echo, etc) and color
it.

$txt = "this is an array('test')";
$pattern = "/(array|break|echo|continue)([\(.|\s.|\;.])/";
echo preg_replace($pattern, '<font color="red">$0</font>', $txt);

This captures "array(" though and I just want "array".

That's because you're using $0 in the replacement.

The value of $0 is the entire string being matched by the regex. In this case, "array(". You only want to put the keyword submatch inside the font tag, then the rest of the matched string after it.

That wasn't a very good explanation.  Sorry, I'm tired.

Anyway, change the preg_replace line to:
echo preg_replace($pattern, '<font color="red">$1</font>$2', $txt);

--Rick

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to