I am having some problems with multiline comments stripping the color from other text.
PHP Code:function cshilite($code)
{
$code = str_replace("<br>", "", $code);
$code = str_replace("<br />", "", $code);
$code = str_replace(">", ">", $code);
$code = str_replace("<", "<", $code);
$code = str_replace(""", "\\"", $code);
$code = str_replace("&", "&", $code);
$code = str_replace('$', '\\$', $code);
$code = str_replace('\\n', '\\\\\\\\n', $code);
$code = str_replace('\\r', '\\\\\\\\r', $code);
$code = str_replace('\\t', '\\\\\\\\t', $code);
$code = stripslashes($code);
$code = htmlentities($code);
$keywords = array('abstract', 'event', 'new', 'struct', 'as', 'explicit', 'null', 'switch', 'base', 'extern', 'object', 'this', 'bool', 'false', 'operator', 'throw', 'break', 'finally', 'out', 'true', 'byte', 'fixed', 'override', 'try', 'case', 'float', 'params', 'typeof', 'catch', 'for', 'private', 'uint', 'char', 'foreach', 'protected', 'ulong', 'checked', 'goto', 'public', 'unchecked', 'class', 'if', 'readonly', 'unsafe', 'const', 'implicit', 'ref', 'ushort', 'continue', 'in', 'return', 'using', 'decimal', 'int', 'sbyte', 'virtual', 'default', 'interface', 'sealed', 'volatile', 'delegate', 'internal', 'short', 'void', 'do', 'is', 'sizeof', 'while', 'double', 'lock', 'stackalloc', 'else', 'long', 'static', 'enum', 'namespace', 'string');
for ($x = 0; $x < count($keywords); $x++) {
$pattern = '/(^|[^a-zA-Z0-9#@_\\'\\"])(' . $keywords[$x] . ')([^a-zA-Z0-9#_\\'\\"]|$)/';
$code = preg_replace($pattern, '\\\\1<font color="blue">\\\\2</font>\\\\3', $code);
}
$single = '/((^|[^(https?|ftp|gopher|irc|news|telnet):])\\/\\/(.*?))([\\r\\n]|$)/is';
if (preg_match_all($single, $code, $match))
{
$return = preg_replace('/<font color=(.*?)>(.*?)<\\/font>/','\\\\2',$match[0]);
$return = preg_replace($single,'<font color="green">\\\\1</font>\\\\4',$return);
$code = str_replace($match[0],$return,$code);
}
$multi = '/(\\/\\*(.*?)(\\*\\/|$))/is';
if (preg_match_all($multi, $code, $match))
{
$return = preg_replace('/<font color=(.*?)>(.*?)<\\/font>/','\\\\2',$match[0]);
$return = preg_replace($multi,'<font color="green">\\\\1</font>',$return);
$code = str_replace($match[0],$return,$code);
}
$spattern = '/(\\"(.*?)[^\\\\\\]")/is';
if (preg_match_all($spattern, $code, $match))
{
$return = preg_replace('/<font color=(.*?)>(.*?)<\\/font>/','\\\\2',$match[0]);
$return = preg_replace($spattern,'\\\\1',$return);
$code = str_replace($match[0],$return,$code);
}
$code = str_replace(""", "\\"", $code);
$code = str_replace("<br>", "", str_replace("<br />", "", $code));
return "<blockquote><pre><smallfont>CSharp Code:</smallfont><hr size=1><br />" . $code . "<hr size=1></pre></blockquote>";
}
