时间:2021-07-01 10:21:17 帮助过:19人阅读
首先下载我们本节课程所需要用到的php实现简单的源码语法高亮函数类库:http://www.gxlcms.com/xiazai/leiku/691
下载完成之后找到我们需要的php类文件,解压至我们本地目录,创建新的php文件!
完成之后,我们要在新的php文件里调用这类,以及实例化该类:
输出 print '</pre>'; ?>
- <?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); //
运行该文件,得到的结果如下图所示:
说明:
这个函数设计的比较简单,可能对某些语法不能高亮显示,你可以自己扩充该函数的功能!
以上就是php实现简单的源码语法高亮的示例分享的详细内容,更多请关注Gxl网其它相关文章!