PHPackages                             potaka/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. potaka/bbcode

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

potaka/bbcode
=============

php parser for bb code

0.2.1(9y ago)41.4k1MITPHPPHP &gt;=7.0CI failing

Since Dec 17Pushed 6y ago1 watchersCompare

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

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

BB code parser for php 7.0+
===========================

[](#bb-code-parser-for-php-70)

Builds:

[![SensioLabsInsight](https://camo.githubusercontent.com/67310e104a0aede12084712f581332eac8a2ab377c629cd9999cf30b1bbcaf49/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f30353436383466612d633264312d346363332d383930352d6434613739373936316332322f6269672e706e67)](https://insight.sensiolabs.com/projects/054684fa-c2d1-4cc3-8905-d4a797961c22)

[![Build Status](https://camo.githubusercontent.com/d464bb8f183b94b7ad863b4e20933a087e16292767c8739b8727be4509c5f43f/68747470733a2f2f7472617669732d63692e6f72672f616e67656c6b2f6262436f64652e7376673f6272616e63683d6a656e6b696e732d696e74656772617469)](https://travis-ci.org/angelk/bbCode)

There are two parts - tokenizer and parser.

Tokenization - convert string to tokens.

BbCodeParser - convert bbCodeTokens to html (+ some validations)

The Easy Way
============

[](#the-easy-way)

```
$tokenizer = new \Potaka\BbCode\Tokenizer\Tokenizer();

$bbText = '[b]bold[/b]text[u]under[i]line[/i][/u]';

$tokenized = $tokenizer->tokenize($text);
$factory = new  \Potaka\BbCode\Factory();
$bbcode = $factory->getFullBbCode();
$html = $bbcode->format($tokenized);
```

The value if `html` is

```
boldtextunderline
```

Installation
============

[](#installation)

```
composer require potaka/bbcode

```

Internal explanation
====================

[](#internal-explanation)

Tokenization
------------

[](#tokenization)

For example

```
$bbText = '[b]bold[/b]text[u]under[i]line[/i][/u]';

```

Will be tokenized to

```
Tag:
  type: null,
  tags:
    tag1:
      type: b
      tags:
        tag1:
          type: null
          text: bold
    tag2:
      type: null
      text: text
    tag3:
      type: u
      tags:
        tag1:
          type: null,
          text: under
        tag2:
          type: i
          tags:
            tag1:
              type: null,
              text: line
```

Tokenized to html
-----------------

[](#tokenized-to-html)

You need to have valid `bb code tags`. Build in tags are available in

Building the parser:

```
use Potaka\BbCode;
use Potaka\BbCode\Tokenizer;

use Potaka\BbCode\Tag\Bold;
use Potaka\BbCode\Tag\Underline;
use Potaka\BbCode\Tag\Italic;

use Potaka\BbCode\Tag\Link;

$bbcode = new BbCode();
```

Lets add the `b` code

```
$bold = new Bold();
$bbcode->addTag($bold);

```

Lets format the token from above

```
$tokenizer = new Tokenizer();
$tokenized = $tokenizer->tokenize($bbText);

$bbcode->format($tokenized);

```

will return

```
boldtext[u]under[i]line[/i][/u]

```

`u` and `i` are not formated cuz tags are not added.

Lets add em.

```
$underline = new Underline();
$bbcode->addTag($underline);

$italic = new Italic();
$bbcode->addTag($italic);

```

Test again

```
$bbcode->format($tokenized);

```

Result:

```
boldtextunder[i]line[/i]
```

Why `i` is not converted? Cuz `u` doesn't allow child tag of type `i`. Lets fix this

```
$bbcode->addAllowedChildTag($underline, $italic);

```

Everything should work now!

Whats the purpose of this allowing? Imagine you have link `[url]http://google.bg[/url]`. What if someone try to put link in link `[url=http://google.bg]google.[url=http://gmail.com]bg[/url][/url]`? This will generate

```

  google.bg

```

This html is invalid. It could even provide [xss](https://en.wikipedia.org/wiki/Cross-site_scripting). This is why you should not allow `url` inside `url`.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~9 days

Total

8

Last Release

3367d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4956cf9ec1a3c884260464c59f06ab8be2befe49fead489b63963b33cb441ace?d=identicon)[po\_taka](/maintainers/po_taka)

---

Top Contributors

[![angelk](https://avatars.githubusercontent.com/u/1329009?v=4)](https://github.com/angelk "angelk (28 commits)")

---

Tags

bbcodebbcodeparserparserphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

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

PHPackages © 2026

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