kuria/php-highlighter
最新稳定版本:v3.0.3
Composer 安装命令:
composer require kuria/php-highlighter
包简介
PHP code highlighter
README 文档
README
PHP code highlighter.
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 filePhpHighlighter::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"><?php</span></li> <li></li> <li><span style="color: #007700">echo </span><span style="color: #DD0000">"Hello 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 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]);
统计信息
- 总下载量: 16.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-13