Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/greg-kennedy/php-bbcode
BBCode to HTML conversion, in PHP.
https://github.com/greg-kennedy/php-bbcode
bbcode html parser php
Last synced: 22 days ago
JSON representation
BBCode to HTML conversion, in PHP.
- Host: GitHub
- URL: https://github.com/greg-kennedy/php-bbcode
- Owner: greg-kennedy
- License: unlicense
- Created: 2019-01-12T23:48:33.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-11-06T06:45:22.000Z (about 3 years ago)
- Last Synced: 2023-02-26T18:52:17.211Z (almost 2 years ago)
- Topics: bbcode, html, parser, php
- Language: PHP
- Size: 29.3 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-bbcode
BBCode to HTML conversion, in PHP7.## What is it?
This is a PHP include that can convert BBCode into safe HTML output.Features:
* UTF-8 aware
* Replaces unsafe HTML characters (`<`, `>`, `&`, ` `) with safe HTML entities (`<`, `>`, `&`, ` `)
* Properly handles various bad input conditions, to ensure correcly closed tags and avoid malformed HTML
* Public-domain (The Unlicense), just copy-paste into your own projects!## What does it support?
These BBCode tags are supported and converted to HTML equivalent:* `[b]`, `[i]`, `[u]`, `[s]`, `[sub]`, `[sup]`
* `[color=X]`, `[size=Y]`, `[font color=X size=Y]`
* `[quote]` / `[blockquote]`
* `[pre]` / `[code]`
* `[ol]`, `[ul]`, `[li]` / `[*]`
* `[table]`, `[tr]`, `[th]`, `[td]`
* `[img]http://www.example.com/image.jpg[/img]`
* `[url]http://www.example.com[/url]` / `[url=http://www.example.com]Example URL[/url]`In addition, unsafe HTML characters are converted to safe HTML entities. Newlines are collapsed and translated as follows:
* `\r` characters are stripped
* Single `\n`: converted to `\n
`
* Two or more sequential `\n`: converted to `\n\n`
The resulting string is whitespace trimmed at beginning and end.
## Notes
The common use case `[quote author=X]` is deliberately excluded, because formatting the result for presentation is implementation-dependent.## Distribution
bbcode.php is the include file. Place it in the folder of your choice and then `include_once 'bbcode.php'`;test.php is a unit test file. You do not need this when deploying.
## Contact
Open an issue if you find a bug. Send a pull request if you want to extend it. I especially like more unit tests, better attempts at catching malformed tags, performance and optimization features.