首先下载我们本节课程所需要用到的php实现简单的源码语法高亮函数类库:
下载完成之后找到我们需要的php类文件,解压至我们本地目录,创建新的php文件!
完成之后,我们要在新的php文件里调用这类,以及实例化该类:
<?php
include_once "codegl.php";//引入文件
//定义
$example_php_code = '
// some code comment:
$example = "foobar";
print $_SERVER["REMOTE_ADDR"];
$array = array(1, 2, 3, 4, 5);
function example_function($str) {
// reverse string
echo strrev($obj);
}
print example_function("foo");
/*
** A multiple line comment
*/
print "Something: " . $example;';
// output the formatted code:
print '<pre>';
print syntax_highlight($example_php_code); //输出
print '</pre>';
?>运行该文件,得到的结果如下图所示:

说明:
这个函数设计的比较简单,可能对某些语法不能高亮显示,你可以自己扩充该函数的功能!
| 欢迎光临 一起源码网 (https://www.171739.xyz/) | Powered by Discuz! X3.3 |