chriskonnertz/bbcode
最新稳定版本:v1.1.2
Composer 安装命令:
composer require chriskonnertz/bbcode
包简介
A naive attempt at a BBCode 'parser' written in PHP. It uses regex and thus fails at complex, nested tags.
关键字:
README 文档
README
A library that parses BBCode and converts it to HTML code. Written in PHP.
Installation
Through Composer:
composer require chriskonnertz/bbcode
From then on you may run composer update to get the latest version of this library.
It is possible to use this library without using Composer but then it is necessary to register an autoloader function.
This library requires PHP 5.5 or higher.
Usage example
Here is a minimalistic example of PHP code that uses this library. It assumes that there is an autoloader.
$bbcode = new ChrisKonnertz\BBCode\BBCode(); $rendered = $bbcode->render('[b]Hello world![/b]'); echo $rendered;
Available tags
[b]: Font style bold -[b]Hello world[/b][i]: Font style italic -[i]Hello world[/i][s]: Font style struck through -[s]Hello world[/s][u]: Font style underlined -[u]Hello world[/u][code]: Code -[code]Hello world[/code][email]: Email (clickable) -[email]test@example.com[/email][url]: URL (clickable) -[url=http://example.com]Example.com[/url][img]: Image (not clickable) -[img]http://example.com/example.png[/img][quote]: Quote -[quote]Hello world[/quote][youtube]: Embedded YouTube video -[youtube]a-video-id-123456[/youtube][font]: Font (name) -[font=Arial]Hello world![/font][size]: Font size -[size=12]Hello world![/size][color]: Font color -[color=red]Hello world![/color][left]: Text-align: left -[left]Hello world[/left][center]: Text-align: center -[center]Hello world[/center][right]: Text-align: right -[right]Hello world[/right][spoiler]: Spoiler (pure HTML code that needs JavaScript code to add behaviour) -[spoiler]Hello world[/spoiler]- List:
[list]: List -[list]...list items...[/list][*]: List item within a list -[*]Hello world!\r\n[*]Hello moon![li]: List item within a list (alias) -[li]Hello world!\r\n[/li][li]Hello moon!/[li]- Full example:
[list][*]Hello world![li]Hello moon![/li][/list]
You can add custom tags with the addTag($name, Closure $closure) method.
Helpful methods
renderRaw($text = null): Renders only the text without any tagsaddTag($name, Closure $closure): Adds a custom tag (with name and a Closure)forgetTag($name): Remove the tag with the given nameignoreTag($name): Add a tag to the array of ignored tagspermitTag($name): Remove a tag from the array of ignored tags
The BBCode class also implements the __toString() method, which internally calls the render() method.
Custom tag example
This code will add a [h1] BBCode tag that creates a <h1> HTML tag:
$bbcode->addTag('h1', function($tag, &$html, $openingTag) { if ($tag->opening) { return '<h1>'; } else { return '</h1>'; } });
Multibyte characters
This library supports the use of multibyte characters.
Fork
This repository originally has been forked from kaimallea/php-bbcode. However, it has been completely rewritten since then.
Status
Status of this repository: Maintained. Create an issue and you will get a response, usually within 48 hours.
chriskonnertz/bbcode 适用场景与选型建议
chriskonnertz/bbcode 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 260.73k 次下载、GitHub Stars 达 40, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bbcode」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chriskonnertz/bbcode 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chriskonnertz/bbcode 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chriskonnertz/bbcode 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony FMBbCodeBundle
Parse your BBCode easy with this library.
BBCode parser
Adds more BBCode
Add visual alerts / warnings to Flarum posts
Library for shortening post text in phpBB 3.2.x
统计信息
- 总下载量: 260.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 41
- 点击次数: 34
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04