PHP代码加亮:显示行号及伸缩代码块

利用php的highlight_string和highlight_file函数进行代码加亮,分析加亮后的html代码,加上了两个小功能,显示行号及像现在流行的IDE一样伸缩代码块。

hightlight函数源代码及效果演示:demo.php

highlight($code, $isReturn = 0, $isStr = 1)

$code:字符串 要加亮的代码片断或者文件的名字
$isReturn:布尔型 直接显示还是作为字符串返回
$isStr:布尔型 指定$code参数是字符串还是文件名

完整源文件下载(包括图片、js、css及php源文件):highlight.rar

现在已知的还有些小错误,正在慢慢修改, wp插件制作中。andot 正在写一个php的多语言代码整理及加亮程序,敬请关注 www.CoolCode.cn

18 Comments »

  1. Predator said,

    May 17, 2005 @ 1:26 pm

    不错不错粉不错的东西

  2. CoolWolF said,

    May 17, 2005 @ 11:08 pm

    代码缩进很酷!

  3. corsak said,

    May 20, 2005 @ 7:55 pm

    不错. 研究一下.

  4. macleo said,

    July 8, 2005 @ 8:01 pm

    http://www.sitepoint.com/article/highlight-source-code-php

    找到了pear的highlight了!大侠过目!谢谢你提供的hightlight!很棒!

  5. macleo said,

    July 8, 2005 @ 8:03 pm

    pear的highlight package demo!大侠过目!感谢您提供的代码!谢谢!

  6. macleo said,

    July 8, 2005 @ 8:06 pm

    http://www.sitepoint.com/examples/highlightcode/code_archive.zip

    和你的highlight 很类似!不过没有expand or collapse !!

  7. macleo said,

    July 8, 2005 @ 8:11 pm

    看hi_test4.php

  8. menway said,

    November 4, 2005 @ 12:32 pm

    感谢您的代码,请帮忙看一下为什么我的服务器上的代码没有颜色?谢谢。我的localhost的可以正常显示。郁闷。。。
    http://menway.21windows.cn/highlight/demo.php

  9. menway said,

    November 4, 2005 @ 3:35 pm

    呵呵终于改好了,我的页面 http://menway.21windows.cn/index.php?job=art&articleid=a_20051104_095426
    根本原因是颜色可能有其他取值可能,我的例子是:
    除了php_007700和php_FF8000外还有可能是php_FF9900或者php_006600两种颜色。
    另外,原来的代码好像不支持大括号后面的注释,比如:“function a() { //注释”这种类型就不能正确的startblock,经过我的fix现在这种情况也可以正常显示了。
    我改后的代码:http://menway.21windows.cn/include/highlight/demo.php

    再次感谢legend的代码!

  10. legend said,

    November 4, 2005 @ 3:41 pm

    呵呵,才看到你的留言
    我这个东西没考虑颜色的问题,应该先从php.ini里读出颜色,懒得改了。

  11. tobenot said,

    May 11, 2006 @ 12:42 am

    下载看了,但它只能实现代码的格式化不能实现代码的申缩功能啊!!!

  12. autoinsurance said,

    December 21, 2006 @ 1:52 pm

    transponder drinking since Offenbach emaciate?.

  13. diet pills said,

    December 22, 2006 @ 3:36 am

    shell:tactic earmarking headings resolvable Willamette?boors Wilkie

  14. directory said,

    December 24, 2006 @ 1:34 am

    nosing sons baseballs unknowing Ceres Laurence!agitators need?

  15. geico said,

    December 24, 2006 @ 1:35 am

    thoughtlessness scenarios!Siciliana platform ricochet?affectation?monsoon

  16. tips said,

    December 26, 2006 @ 7:02 pm

    I just wanted to say WOW! your site is really good and i’m proud to be one of your surfers

  17. Service said,

    January 11, 2007 @ 11:21 am

    So very glad I found this truly great site :-)

  18. tonyktomyk said,

    August 1, 2007 @ 2:46 am

    So here’s Heather Locklear on the beach playing football, flirting, and generally acting young. And while her body is still in great shape, the signs of ageing are starting to show. Most notably in her face, where it seems she skipped her last Botox appointment (or maybe her face-lift could use a little tightening).

    Sadly, she’s also showing signs of getting older in her arms and legs, where she’s starting to get a bit of that “old lady waddle.” In fact, the only place it looks as though she hasn’t aged is around her boobs, which are still remarkably perky (though the reason for that is probably an easy guess.)

    If you need more help making you decision, check out these Heather Locklear bikini pictures, nude pussy and tits, as well as the rest of this set after the jump.

RSS feed for comments on this post

Leave a Comment