Here's the function I just wrote to solve the same problem. Hope it helps! (call this instead of highlight_string) It works with full open tags only, if you want to also support short open tags it would take some reworking, but you should get the idea.
<?php
function PHPHighlight($str) {
$added = FALSE;
$firstopen = strpos($str,'<?php');
$firstclose = strpos($str,'?>');
if( $firstopen === FALSE ) {
$str = '<?php '.$str;
$added = TRUE;
} elseif( $firstclose !== FALSE && $firstclose < $firstopen ) {
$str = '<?php '.$str;
$added = TRUE;
}
$str = highlight_string($str,TRUE);
if( $added === TRUE ) {
$open = substr($str,0,37);
$close = substr($str,87);
$str = $open.$close;
}
return $str;
}