Here is the best way to highlight code if you want classes instead of inline styles:
<?php
function highlightcode($text){
ini_set("highlight.comment", "c-comment");
ini_set("highlight.default", "c-default");
ini_set("highlight.html", "c-default");
ini_set("highlight.keyword", "c-keyword");
ini_set("highlight.string", "c-string");
$text =
trim(
str_replace(
'<br />',
"\n", str_replace(
[
"<span style=\"color: c-default\">\n<?php ",
"<code>",
"</code>"
],
"",
highlight_string("<?php " . $text, true)
)
)
);
$classes = ["c-comment", "c-default", "c-keyword", "c-string"];
foreach($classes as $class){
$text = str_replace('<span style="color: ' . $class . '">', '<span class="' . $class . '">', $text);
}
return $text;
}
?>
Generates output that looks like this:
<span class="c-keyword">if(</span>condition<span class="c-keyword">){
echo </span><span class="c-string">"HTML here"</span><span class="c-keyword">;
}</span>
Hope this helps.