2017 © Pedro Peláez
 

library bbcode

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

image

chriskonnertz/bbcode

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

  • Sunday, June 17, 2018
  • by siconize
  • Repository
  • 2 Watchers
  • 6 Stars
  • 1,508 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 5 Forks
  • 5 Open issues
  • 9 Versions
  • 25 % Grown

The README.md

BBCode

Build Status GitHub license Version, (*1)

A library that parses BBCode and converts it to HTML code. Written in PHP., (*2)

Installation

Through Composer:, (*3)

composer require chriskonnertz/bbcode

From then on you may run composer update to get the latest version of this library., (*4)

It is possible to use this library without using Composer but then it is necessary to register an autoloader function., (*5)

This library requires PHP 5.5 or higher., (*6)

Usage example

Here is a minimalistic example of PHP code that uses this library. It assumes that there is an autoloader., (*7)

$bbcode = new ChrisKonnertz\BBCode\BBCode();

$rendered = $bbcode->render('[b]Hello world![/b]');

echo $rendered;

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., (*8)

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., (*9)

Custom tag example

This code will add a [h1] BBCode tag that creates a <h1> HTML tag:, (*10)

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

Multibyte characters

This library supports the use of multibyte characters., (*11)

Fork

This repository originally has been forked from kaimallea/php-bbcode. However, it has been completely rewritten since then., (*12)

Status

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

The Versions

17/06 2018

dev-2.0-dev

dev-2.0-dev

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

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

The Development Requires

by Chris Konnertz
by Kai Mallea

bbcode

17/06 2018

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

The Development Requires

by Chris Konnertz
by Kai Mallea

bbcode

17/06 2018

v1.1.2

1.1.2.0

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

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

The Development Requires

by Chris Konnertz
by Kai Mallea

bbcode

31/01 2018

v1.1.1

1.1.1.0

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

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

The Development Requires

by Chris Konnertz
by Kai Mallea

bbcode

30/01 2018

v1.1.0

1.1.0.0

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

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

The Development Requires

by Chris Konnertz
by Kai Mallea

bbcode

24/01 2018

v1.0.2

1.0.2.0

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

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

The Development Requires

by Chris Konnertz
by Kai Mallea

bbcode

26/09 2017

v1.0.1

1.0.1.0

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

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

The Development Requires

by Chris Konnertz
by Kai Mallea

bbcode

26/09 2017

dev-substr-replacement

dev-substr-replacement

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

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

by Chris Konnertz
by Kai Mallea

bbcode

13/05 2017

v1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

by Chris Konnertz
by Kai Mallea

bbcode