Like you see in the example above, you can even add additional styles like bold text, since the values are set directly to the DOM attribute "style".

Also, this function highlights only text, if it begins with the prefix "<?php". But this function can highlight other similar formats too (not perfectly, but better than nothing), like HTML, XML, C++, JavaScript, etc. I use following function to highlight different file types and it works quite good:

Here is an improved version of Dimitry's xml_highlight function.I fixed a bug which replaced the first character of the tags name,and added a line to replace the tabs and spaces withnon-breaking space symbols to keep the identation.

When you quote highlighted PHP code in your website you need to escape quotes. If you quote a lot it may be annoyning. Here is tiny snippet how to make quoting tidy and clean. Write your code like this:

This function outputs valid XHTML 1.1 code by replacing font tags with span tags. You can also specify whether you want it to return or echo, output a line-count, the color of the line-count, and the starting line-count number.

I didn't get the expected results from the other XHTML_highlight function, so I developed my own and it is much more efficient. The older one uses a preg_replace to replace the contents of the tag to within a span tag. The only preg_replace in my function pulls the color attribute, and puts it within a str_replace'd span tag.

The documentation says for the first parameter "The PHP code to be highlighted. This should include the opening tag. ". But it seems that the code should not only but *must* start with PHP's opening tag or otherwise the function will still modify but will not highlight the code.

This fonction replaces every space with the html code &nbsp; (non-breaking space)this is not very good because text will not go to the line and causes a big widthfor example in a bordered div, text will go across the border

I read the note from "stanislav dot eckert at vizson dot de" and I really enjoyed the function he created.For my use I made some adaptations leaving the function more practical and allowing the passage and multiple parameters at a time, I also modified the style of the <code> element with a black background and margins.

I wanted to build a better function and exclude operators {}=- from keywords span class. I also wanted to link functions used in my PHP code directly to the PHP site.A lot more changes and tweaks have been made and the output is much better!

This hasn't been mentioned, but it appears that PHP opening and closing tags are required to be part of the code snippet.<?php highlight_string("<? \$var = 15; ?>"); ?>works, while<?php highlight_string("\$var = 15;"); ?>does not. This is unforunate for those of use who want to show tiny code snippets, but there you go. Earlier versions of this function did not have this requirement, if I remember correctly.

Fully working, XHTML 1.1 ready xhtml_highlight function. I included the stripslashes, because of some problems I had with out it. It should be safe to leave it in there, but if you experience problems, feel free to take it out.

In some cases, I found that it's useful to have highlight_string format <code>...</code> inline as part of a paragraph, and other times, as a block for demonstrating multiple lines of code. I made this function to help out.