PHPackages                             chriskonnertz/bbcode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. chriskonnertz/bbcode

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

chriskonnertz/bbcode
====================

A naive attempt at a BBCode 'parser' written in PHP. It uses regex and thus fails at complex, nested tags.

v1.1.2(7y ago)41272.2k↓12.8%27[4 PRs](https://github.com/chriskonnertz/bbcode/pulls)2MITPHPPHP &gt;=5.3.7CI failing

Since May 13Pushed 3y ago3 watchersCompare

[ Source](https://github.com/chriskonnertz/bbcode)[ Packagist](https://packagist.org/packages/chriskonnertz/bbcode)[ RSS](/packages/chriskonnertz-bbcode/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (8)Used By (2)

BBCode
======

[](#bbcode)

[![Build Status](https://camo.githubusercontent.com/0783bece2f97713151fc88a8526c78c55628d7068efef39b2ae60d5c02e14dd1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f63687269736b6f6e6e6572747a2f6262636f64652e737667)](https://travis-ci.org/chriskonnertz/bbcode)[![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/chriskonnertz/bbcode/master/LICENSE)[![Version](https://camo.githubusercontent.com/343e84dc36e737e928019465f41bc6f0f5e594cd79e56cd50b1d4df4e787a5ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63687269736b6f6e6e6572747a2f6262636f64652e737667)](https://packagist.org/packages/chriskonnertz/bbcode)

A library that parses BBCode and converts it to HTML code. Written in PHP.

Installation
------------

[](#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](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md#example-implementation).

> This library requires PHP 5.5 or higher.

Usage example
-------------

[](#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
--------------

[](#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
---------------

[](#helpful-methods)

- `renderRaw($text = null)`: Renders only the text without any tags
- `addTag($name, Closure $closure)`: Adds a custom tag (with name and a Closure)
- `forgetTag($name)`: Remove the tag with the given name
- `ignoreTag($name)`: Add a tag to the array of ignored tags
- `permitTag($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
------------------

[](#custom-tag-example)

This code will add a `[h1]` BBCode tag that creates a `` HTML tag:

```
$bbcode->addTag('h1', function($tag, &$html, $openingTag) {
    if ($tag->opening) {
        return '';
    } else {
        return '';
    }
});
```

Multibyte characters
--------------------

[](#multibyte-characters)

This library supports the use of multibyte characters.

Fork
----

[](#fork)

This repository originally has been forked from [kaimallea/php-bbcode](https://github.com/kaimallea/php-bbcode). However, it has been completely rewritten since then.

Status
------

[](#status)

Status of this repository: **Maintained**. Create an issue and you will get a response, usually within 48 hours.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 70.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~79 days

Recently: every ~65 days

Total

6

Last Release

2892d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2548d359f2033681fd886f21a31406119a9ea3bd93dbec6f533f75f006f09228?d=identicon)[siconize](/maintainers/siconize)

---

Top Contributors

[![chriskonnertz](https://avatars.githubusercontent.com/u/4319323?v=4)](https://github.com/chriskonnertz "chriskonnertz (80 commits)")[![kaimallea](https://avatars.githubusercontent.com/u/228982?v=4)](https://github.com/kaimallea "kaimallea (33 commits)")

---

Tags

bbcodeconverterhtmlparserphpbbcode

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chriskonnertz-bbcode/health.svg)

```
[![Health](https://phpackages.com/badges/chriskonnertz-bbcode/health.svg)](https://phpackages.com/packages/chriskonnertz-bbcode)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[thunderer/shortcode

Advanced shortcode (BBCode) parser and engine for PHP

3892.6M44](/packages/thunderer-shortcode)[mck89/peast

Peast is PHP library that generates AST for JavaScript code

18934.7M29](/packages/mck89-peast)[ivopetkov/html5-dom-document-php

HTML5 DOMDocument PHP library (extends DOMDocument)

6031.4M49](/packages/ivopetkov-html5-dom-document-php)[ergebnis/json

Provides a Json value object for representing a valid JSON string.

2521.7M8](/packages/ergebnis-json)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
