Mam funkcje kolorowania składni php z coyot'a 0.9.0 (chyba albo 0.9.1) i nieco ją przerobiłem ale mam problem z \" a mianowicie:
jeśli mam takie coś:
Kod
$text = "jakiś sobie tekst w całości pokolorowany";
to mi go poprawnie koloruje ale jeśli w kodzie znajdzie się \" to już zaczynają sie schodzy:
Kod
$text = "jakiś sobie tekst pokolorowany \"ten tekst nie jest pokolorowany \"a ten już jest";
i jak to teraz poprawić by ignorował znaki " poprzedzone \




oto f-cja:
<?php function PHPHighlight($body) { //wyodrębnienie zawartosci calego tekstu z wnetrza <php></php> //usuwanie znacznikow HTML //dzielenie tokenów komentarzy i stringów # /* */ // ' \" ` ' $result = \"\"; //teraz dla tokenów jazda !! for( $j = 0; $j < $tokens_count; $j++ ) { //pogrubianie slów kluczowych $token = $tokens[$j]; $token = preg_replace( \"/b$PHP_RESERVED[$w]b/i\", \"<font color=\"#0000ff\">$PHP_RESERVED[$w]</font>\", $token ); } //kolorowanie liczb //kolorowanie zmiennych $token = preg_replace( \"/($[0-9a-zA-Z_]+)/i\", \"<font color=\"#007700\">1</font>\", $token ); $result .= $token; //sprawdzanie komentarzy: komentarze i stringi sa parsowane BEZ sprawdzania słów k
luczowych wewnątrz switch( $separators[0][$j] ) { case \"/*\": { $result .= \"<font color=\"c0c0c0\\"><i>/*\"; while( ( $j < $tokens_count - 1 ) && ( $separators[0][++$j] != \"*/\" ) ) { $result .= $tokens[$j].$separators[0][$j]; } $result .= $tokens[$j].$separators[0][$j].\"</i></font>\"; break; } case \"#\": { $result .= \"<font color=\"c0c0c0\\"><i>#\"; while( ( $j < $tokens_count - 1 ) && ( $separators[0][++$j] != \"n\" ) ) { $result .= $tokens[$j].$separators[0][$j]; } $result .= $tokens[$j].$separators[0][$j].\"</i></font>\"; break; } case \"//\": { $result .= \"<font color=\"c0c0c0\\"><i>//\"; while( ( $j < $tokens_count - 1 ) && ( $separators[0][++$j] != \"n\" ) ) { $result .= $tokens[$j].$separators[0][$j]; } $result .= $tokens[$j].$separators[0][$j].\"</i></font>\"; break; } case \"'\": { $result .= \"<font color=\"ff0000\\">'\"; while( ( $j < $tokens_count - 1 ) && ( $separators[0][++$j] != \"'\" ) ) { $result .= $tokens[$j].$separators[0][$j]; } $result .= $tokens[$j].$separators[0][$j].\"</font>\"; break; } case \"\"\": { $result .= \"<font color=\"ff0000\">\"\"; while( ( $j < $tokens_count - 1 ) && ( $separators[0][++$j] != \"\"\" ) ) { $result .= $tokens[$j].$separators[0][$j]; } $result .= $tokens[$j].$separators[0][$j].\"</font>\"; break; } case \"`\": { $result .= \"<font color=\"ff0000\\">`\"; while( ( $j < $tokens_count - 1 ) && ( $separators[0][++$j] != \"`\" ) && ( $separators[0][$j] != \"n\" ) ) { $result .= $tokens[$j].$separators[0][$j]; } $result .= $tokens[$j].$separators[0][$j].\"</font>\"; break; } default: $result .= $separators[0][$j]; } } $body = str_replace('<php>' . $matched[1][$i] . '</php>', '<font face=\"Courier New\">' . $result. '</font>', $body); } return $body; } ?>
powyższa f-cja pochodzi z Coyot'a