note 64100 deleted from function.highlight-string by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 14:58:03 +0000 |
| Subject: | note 64100 deleted from function.highlight-string by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197248@lists.php.net to get a copy of this message | ||
Note Submitter: m dot lebkowski+phpnet at gmail dot com
----
stalker, I`m afraid your function has a bug. Whenever a input string will contain a substring:
'color="foo.bar"' it will be replaced by your function, whitch is of course
incorrect. Try this:
<?php
function xhtmlHighlightString( $str, $return=false )
{
$hlt = highlight_string( $str, true );
$ret = str_replace(
array( '<font color="', '</font>' ),
array( '<span style="color: ', '</span>' ),
$hlt );
if($return)
return $ret;
echo $ret;
return true;
}
function xhtmlHilightFile( $path, $return = false )
{
return xhtmlHighlightString( file_get_contents( $path ), $return );
} ?>