定制 kuria/php-highlighter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kuria/php-highlighter

Composer 安装命令:

composer require kuria/php-highlighter

包简介

PHP code highlighter

README 文档

README

PHP code highlighter.

https://travis-ci.com/kuria/php-highlighter.svg?branch=master

Contents

Features

  • highlighting files or strings
  • highlighting specific line ranges
  • marking an active line
  • produces an ordered list (<ol>) with corresponding line numbers

Requirements

  • PHP 7.1+

Usage

Highlighting code

  • PhpHighlighter::file() - highlight a PHP file
  • PhpHighlighter::code() - highlight a string of PHP code
<?php

use Kuria\PhpHighlighter\PhpHighlighter;

$php = <<<'PHP'
<?php

echo "Hello world!";

PHP;

echo PhpHighlighter::code($php);

Output:

<ol>
<li><span style="color: #0000BB">&lt;?php</span></li>
<li></li>
<li><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;world!"</span><span style="color: #007700">;</span></li>
<li></li>
</ol>

Note

In PHP 8.3, output of the highlight_file() and highlight_string() functions (which are used internally) has changed.

If you're using PHP 8.3 or newer, the output will contain regular spaces instead of &nbsp; entities. You can use white-space: pre; in your CSS to fix this.

Marking an active line

An active line can be specified using the second argument.

The active line will have a class="active" attribute.

<?php

echo PhpHighlighter::code($php, 3);

Specifying line range

A line range can be specified using the third argument.

Example line ranges:

  • NULL - highlight all lines
  • [20, 30] - highlight lines from 20 to 30 (absolute)
  • [-5, 5] - highlight 5 lines around the active line (requires active line)
  • [0, 0] - highlight the active line only (requires active line)
<?php

echo PhpHighlighter::code($php, 3, [-1, 1]);

kuria/php-highlighter 适用场景与选型建议

kuria/php-highlighter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.78k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 01 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「highlighter」 「highlight_file」 「highlight_string」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kuria/php-highlighter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kuria/php-highlighter 我们能提供哪些服务?
定制开发 / 二次开发

基于 kuria/php-highlighter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-13