Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/igorakaamigo/php5-tiny-bbcode

A tiny BBCode implementation for PHP5.4+
https://github.com/igorakaamigo/php5-tiny-bbcode

bbcode bbcode-parser php php5 phpunit tdd tdd-kata

Last synced: 5 days ago
JSON representation

A tiny BBCode implementation for PHP5.4+

Awesome Lists containing this project

README

        

# Tiny BBCode implementation for PHP 5.4+ and HHVM

This library includes a lightweight implementation of a BBCode subset to HTML translator.

[![License](https://img.shields.io/github/license/igorakaamigo/php5-tiny-bbcode.svg)](https://github.com/igorakaamigo/php5-tiny-bbcode/blob/master/LICENSE)
[![Packagist Version](https://img.shields.io/packagist/v/igorakaamigo/php5-tiny-bbcode.svg)](https://packagist.org/packages/igorakaamigo/php5-tiny-bbcode)
[![Minimal PHP Version](https://img.shields.io/packagist/php-v/igorakaamigo/php5-tiny-bbcode.svg)](http://php.net/downloads.php)

## Features

* It's tiny, yep.
* PSR-4 autoloading compliant structure
* Unit-Testing with PHPUnit
* Easy to use to any framework or even a plain php file

## Installation

The suggested installation method is via [composer](https://getcomposer.org/):

```sh
php composer.phar require "igorakaamigo/php5-tiny-bbcode"
```

## Usage

```php
use \Igorakaamigo\Utils\BBCode;

echo BBCode::convert('[b]A bold string[/b]');
// Outputs: A bold string

echo BBCode::convert('A text');
// Outputs: <span>A text</span>

echo BBCode::convert('[i]Hi there![/i]');
// Outputs: Hi&nbsp;there!

echo BBCode::convert('[i]Hi there
!!![/i]', [' ', '
']);
// Outputs: Hi there
!!!

echo BBCode::convert('Magic links: email me at [email protected]');
// Outputs: Magic links: email me at [email protected]

echo BBCode::convert('Magic links: http://www.domain.tld/path/to/resource');
// Outputs: Magic links: http://www.domain.tld/path/to/resource
```

### Supported BBCodes

* [b]Bold string[/b]
* [i]Italic string[/i]
* [u]Underline string[/u]
* [s]Strikethrough string[/s]
* [email][email protected][/email]
* [url]http://www.domain.tld[/url]
* [url="http://www.domain.tld"]Another way to render a link[/url] (quotes inside url tag are not necessary)
* [img]http://www.domain.tld/upload/image.png[/img]
* [quote]A quotation[/quote]
* [quote="Quote author"]A quotation[/quote] (quotes inside quote tag are not necessary)
* [code]A program code sample[/code]
* [size="12"]A text written using a 12px-sized font[/size] (quotes inside size tag are not necessary)
* [size="10pt"]A text written using a 10pt-sized font[/size] (quotes inside size tag are not necessary)
* [color="#33FF33"]A green text line[/color] (quotes inside color tag are not necessary)
* [table], [tr], [td] – table-related tags
* [ul], [ol], [li], [*], [list], [list=1|a|A|i|I], [list="1|a|A|i|I"] – list-related tags

[attachment] tag is not supported yet.

## Contributing

Just a kata project. Anyway – if one is interested –

Fork --> modify --> pull-request