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

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

codedepp/bbcode
===============

BBCode parser from or to HTML.

0405PHP

Since Aug 23Pushed 6y agoCompare

[ Source](https://github.com/codedepp/bbcode)[ Packagist](https://packagist.org/packages/codedepp/bbcode)[ RSS](/packages/codedepp-bbcode/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

BBCode
======

[](#bbcode)

[![Latest Version](https://camo.githubusercontent.com/b59e8ea7e2a379e552ebd9a62e29b26d2acd9a2f10c502aadc3b2b662921ca83/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f636f6465646570702f6262636f64652e7376673f7374796c653d666c61742d737175617265)](https://github.com/codedepp/bbcode/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

> BBCode parser from or to HTML.

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

[](#installation)

[PHP](https://php.net) 7.1+ is required.

To get the latest version of BBCode, simply require the project using [Composer](https://getcomposer.org):

```
$ composer require codedepp/bbcode
```

Usage
-----

[](#usage)

### `convertFromHtml(string $text)`

[](#convertfromhtmlstring-text)

Convert BBCode to HTML and returns parsed text as string.

Example:

```
use Codedepp\BBCode\BBCode;

$bbCode = new BBCode();

// Output: '[b]Hello word![/b]'
$bbCode->convertFromHtml('Hello word!');
```

### `convertToHtml(string $text, [$caseSensitive])`

[](#converttohtmlstring-text-casesensitive)

Convert HTML to BBCode and returns parsed text as string.

Example:

```
use Codedepp\BBCode\BBCode;

$bbCode = new BBCode();

// Output: 'Hello word!'
$bbCode->convertToHtml('[b]Hello word![/b]');
```

This function also supports case sensitive BBCode parsing by optional parameter.

To enable this, simply pass `BBCode::CASE_SENSITIVE` as second argument:

```
// Output: 'Random text'
$bbCode->convertToHtml('[B][I][U]Ran[b]d[/b]om text[/u][/I][/b]', BBCode::CASE_SENSITIVE);
```

### `stripBBCodeTags(string $text)`

[](#stripbbcodetagsstring-text)

Strips BBCode tags from text and returns output as string.

Example:

```
use Codedepp\BBCode\BBCode;

$bbCode = new BBCode();

// Output: 'Hello word!'
$bbCode->stripBBCodeTags('[b]Hello word![/b]');
```

### `only(array list or ...args)`

[](#onlyarray-list-or-args)

Sets parser to only convert set BBCode tags.

Example:

```
use Codedepp\BBCode\BBCode;

$bbCode = new BBCode();

// Output: 'Bold [i]italic[/i]'
$bbCode->only('bold')->convertToHtml('[b]Bold[/b] [i]italic[/i]');

// Or as array
$bbCode->only(['bold'])->convertToHtml('[b]Bold[/b] [i]italic[/i]');
```

### `except(array list or ...args)`

[](#exceptarray-list-or-args)

Sets parser to only convert all BBCode tags except listed.

Example:

```
use Codedepp\BBCode\BBCode;

$bbCode = new BBCode();

// Output: '[b]Bold[/b] italic'
$bbCode->except('bold')->convertToHtml('[b]Bold[/b] [i]italic[/i]');

// Or as array
$bbCode->except(['bold'])->convertToHtml('[b]Bold[/b] [i]italic[/i]');
```

### `addParser(string $name, string $pattern, string $replace, string $content)`

[](#addparserstring-name-string-pattern-string-replace-string-content)

Add regex based BBCode parser to translate found pattern to desired one.

Example:

```
use Codedepp\BBCode\BBCode;

$bbCode = new BBCode();

// Add "[link target=http://example.com]Example[/link]" parser.
$bbCode->addParser(
    'custom-link',
    '/\[link target\=(.*?)\](.*?)\[\/link\]/s',
    '$2',
    '$1'
);

// Output: 'Text to be displayed.'
$bbCode->convertToHtml('[link target=www.yourlinkhere.com]Text to be displayed[/link].');
```

### `addHtmlParser(string $name, string $pattern, string $replace, string $content)`

[](#addhtmlparserstring-name-string-pattern-string-replace-string-content)

Add HTML parser to translate pattern to desired one.

See `addParser` for example code.

### `addLinebreakParser()`

[](#addlinebreakparser)

Adds linebreak parser to BBCode parsers list to convert newlines to `` in HTML.

Laravel installation
--------------------

[](#laravel-installation)

Once BBCode is installed, you need to register the service provider. Open up `config/app.php` and add the following to the `providers` key.

- `\Codedepp\BBCode\BBCodeServiceProvider::class,`

You can register facades in the `aliases` key of your `config/app.php` file if you like.

- `'BBCode' => \Codedepp\BBCode\Facades\BBCode::class,`

With registered facade, you can use library's functionality as following:

```
// Output: 'Laravel wins'
echo BBCode::convertToHtml('[b]Laravel wins[/b]');

// Output: '[b]Do Symphony or not[/b]'
echo BBCode::convertFromHtml('Do Symphony or not');

// Output: 'What does [i]fox say[/i]'
echo BBCode::only('bold')->convertToHtml('[b]What does[/b] [i]fox say[/i]');
```

Testing
-------

[](#testing)

To run tests, simply run following command in terminal:

```
composer test
```

Contributions &amp; Issues
--------------------------

[](#contributions--issues)

Contributions are welcome. Please clearly explain the purpose of the PR and follow the current style.

Issues can be resolved quickest if they are descriptive and include both a reduced test case and a set of steps to reproduce.

Licence
-------

[](#licence)

The `codedepp/bbcode` library is copyright © [Codedepp](http://codedepp.com) and licensed for use under the MIT License (MIT).

Please see [MIT License](LICENSE) for more information.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f681952e00395632597d9020518a826f64081a9f110dc911f63c9c56e72a4fae?d=identicon)[codedepp](/maintainers/codedepp)

---

Top Contributors

[![codedepp](https://avatars.githubusercontent.com/u/37926797?v=4)](https://github.com/codedepp "codedepp (1 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/codedepp-bbcode/health.svg)](https://phpackages.com/packages/codedepp-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)
