Download the PHP package devristo/bbcode without Composer
On this page you can find all versions of the php package devristo/bbcode. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devristo/bbcode
More information about devristo/bbcode
Files in devristo/bbcode
Package bbcode
Short Description A simple yet flexible BBCode parser for PHP 5.4 and higher.
License BSD-2-Clause
Informations about the package bbcode
bbcode
A simple yet flexible BBCode parser for PHP 5.4 and higher.
Features
- Transforms BBCode documents to a . Can be altered using its API or queried using XPath.
- Annotates smileys and urls in text nodes
- Flexible recursive rendering mechanism.
Installation
The easiest way to get started is by using composer. Since the API is not finalised you need to refer to devristo/bbcode as follows:
Minimal example
For basic BBCode devristo/bbcode offers out of the box support. This is the case for [b], [i], [img], [s], [u] and [url] tags.
Transforming BBCode to a DOMDocument
Internally devristo/bbcode parses BBCode into a DOMDocument before rendering its content to HTML.
Linkification
By default devristo/bbcode annotates all links by creating an url element in the DOM tree. You can disable this behaviour using . The following example uses linkification and the generated DOM model to query all urls used in the BBCode.
Emoticons
Similar to links devristo/bbcode annotates emoticons with the emoticon tag in the DOM tree. Emoticons are matched on word basis and must be defined using . They can be parsed by setting a decorator for 'emoticon' elements.
Defining new tags and their decorators
Eventhough all possible BBCode tags are parsed into the DOM, unknown tags will be rendered by the which outputs the originally fed BBCode. To render a tag in a different way its decorator should be set to the RenderContext.
You can override internal devristo/bbcode decorators by simple setting the decorator for the tags explicitly. If you want to disable all internal decorators simply call before defining your own.
Altering RenderContext on-the-fly
Often you might want to change the rendering of decendent elements of a specific tag. For example we could define a [quote] tag, and render nested quotes differently.
Retrieving raw BBCode
Sometimes we are content with the raw contents of an element. A good example is the following [code] tag, which renders everything between code-tags as is.