PHPackages                             ambitionphp/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. ambitionphp/bbcode

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

ambitionphp/bbcode
==================

BBCode parser from or to HTML.

1.1.2(7y ago)112MITPHP

Since Jul 14Pushed 6y agoCompare

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

READMEChangelogDependencies (1)Versions (9)Used By (0)

BBCode
======

[](#bbcode)

[![Latest Version](https://camo.githubusercontent.com/c5b2823d447a30d97b312a50273ae527e2b53302a62f1ccd4f435a33a769488e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f67656e6572742f6262636f64652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Genert/bbcode/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/ad2b3e505783a48966b02bd024ff6de9c8b776258499853d72d76756649c6e9e/68747470733a2f2f7472617669732d63692e6f72672f47656e6572742f6262636f64652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Genert/bbcode)

> 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 genert/bbcode
```

Usage
-----

[](#usage)

### `convertFromHtml(string $text)`

[](#convertfromhtmlstring-text)

Convert BBCode to HTML and returns parsed text as string.

Example:

```
use Genert\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 Genert\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 Genert\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 Genert\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 Genert\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 Genert\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.

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

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

- `'BBCode' => \Genert\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 `genert/bbcode` library is copyright © [Genert Org](http://genert.org) and licensed for use under the MIT License (MIT).

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

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 54.5% 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 ~77 days

Recently: every ~115 days

Total

7

Last Release

2767d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ddff88901fe95772277efdefb74ba68d41c212f61d4ad6dc2ac369dc688c63a?d=identicon)[ambitionphp](/maintainers/ambitionphp)

---

Top Contributors

[![genert](https://avatars.githubusercontent.com/u/1218788?v=4)](https://github.com/genert "genert (6 commits)")[![ua2004](https://avatars.githubusercontent.com/u/8424744?v=4)](https://github.com/ua2004 "ua2004 (3 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (2 commits)")

---

Tags

laravelparserPSR-4PSR-2bbcodePSR-1

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[genert/bbcode

BBCode parser from or to HTML.

81324.0k1](/packages/genert-bbcode)[icamys/php-sitemap-generator

Simple PHP sitemap generator.

175342.8k6](/packages/icamys-php-sitemap-generator)[evilfreelancer/routeros-api-php

Modern Mikrotik RouterOS API PHP client for your applications (with Laravel support)

491206.1k4](/packages/evilfreelancer-routeros-api-php)[authbucket/oauth2-php

The standard compliant OAuth2.0 library based on the Symfony Components

82107.6k4](/packages/authbucket-oauth2-php)[pherum/laravel-bbcode

Parse your BBCode easy with this library.

2427.5k](/packages/pherum-laravel-bbcode)

PHPackages © 2026

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