In our daily development work, we will find that in the display of the Web page, a lot of code is highlighted, so that the effect is to make the page more beautiful, so that the user experience more intuitive Web page, then today we will introduce you how to use PHP to achieve the effect of code highlighting!
First download the PHP that we need for this lesson to implement a simple source syntax highlighting function class Library: http://www.php.cn/xiazai/leiku/691
After the download, find the PHP class files we need, unzip to our local directory, create a new PHP file!
Once this is done, we will invoke this class in the new PHP file, and instantiate the class:
<?phpinclude_once "codegl.php";//import file//Definition $example_php_code = '//Some code comment: $example = "Foobar";p rint $_ server["REMOTE_ADDR"]; $array = Array (1, 2, 3, 4, 5); function Example_function ($STR) { //reverse string echo STRR EV ($obj);} Print example_function ("foo");/*** A multiple Line Comment*/print "Something:". $example; '; /Output the formatted code:print ' <pre> ';p rint syntax_highlight ($example _php_code); Output print ' </pre> ';? >
Run the file and get the results as shown:
Description
This function design is relatively simple, you may not highlight some of the syntax, you can expand the function of the functions!