On Friday, November 28, 2003, at 12:17 AM, pete M wrote:
What Preg_replace code would I need to highlight all the code within
the script /script tags in red.. (case insensitive)
What I want is a view_source.php page to highlight the javascript for
a tutorial I'm writing. Can view the source ok but need to highlight
the code.
Not a regular expression expert ;-(
UNTESTED:
?
$old = before before
script type='text/javascript'
function foo()
{
// bah
}
/script
after after;
// i assume the source will have htmlentities applied...
$old = htmlentities($old);
// ...therefore we need to match on lt; and gt; rather than and
$new =
preg_replace('/lt;script(.*?)gt;(.*?)lt;\/scriptgt;/
s','lt;script\\1gt;span
style=color:red;\\2/spanlt;/scriptgt;',$old);
echo pre{$new}/pre;
?
season to taste :)
Justin French
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php