Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pherum/laravel-bbcode
Parse your BBCode easy with laravel-bbcode
https://github.com/pherum/laravel-bbcode
bbcode laravel laravel-bbcode
Last synced: about 1 month ago
JSON representation
Parse your BBCode easy with laravel-bbcode
- Host: GitHub
- URL: https://github.com/pherum/laravel-bbcode
- Owner: PheRum
- License: mit
- Created: 2017-12-27T15:14:14.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-11T20:42:25.000Z (over 3 years ago)
- Last Synced: 2024-11-08T06:20:24.650Z (about 2 months ago)
- Topics: bbcode, laravel, laravel-bbcode
- Language: PHP
- Size: 16.6 KB
- Stars: 23
- Watchers: 3
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel BBCode
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![Build Status][ico-travis]][link-travis]
[![StyleCI][ico-styleci]][link-styleci]
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]## Description
Parse your BBCode easy with laravel-bbcode
## Install
Via Composer
``` bash
composer require pherum/laravel-bbcode
```## Usage
To parse some text it's as easy as this!
``` php
$bbcode = new PheRum\BBCode\BBCodeParser;echo $bbcode->parse('[b]Bold Text![/b]');
// Bold Text!
```
Would like the parser to not use all bbcodes? Just do like this.
``` php
$bbcode = new PheRum\BBCode\BBCodeParser;echo $bbcode->only('bold', 'italic')
->parse('[b][u]Bold[/u] [i]Italic[/i]![/b]');
// [u]Bold[/u] Italic!echo $bbcode->except('bold')
->parse('[b]Bold[/b] [i]Italic[/i]'); // [b]Bold[/b] Italic
```By default the parser is case sensitive. But if you would like the parser to accept tags like `` [B]Bold Text[/B] `` it's really easy.
``` php
$bbcode = new PheRum\BBCode\BBCodeParser;// Case insensitive
echo $bbcode->parse('[b]Bold[/b] [I]Italic![/I]', true); // Bold Italic!// Or like this
echo $bbcode->parseCaseInsensitive('[b]Bold[/b] [i]Italic[/i]');
// Bold Italic!
```
You could also make it more explicit that the parser is case sensitive by using another helper function.
``` php
$bbcode = new PheRum\BBCode\BBCodeParser;echo $bbcode->parseCaseSensitive('[b]Bold[/b] [I]Italic![/I]');
// Bold [I]Italic![/I]
```If you would like to completely remove all BBCode it's just one function call away.
``` php
$bbcode = new PheRum\BBCode\BBCodeParser;echo $bbcode->stripBBCodeTags('[b]Bold[/b] [i]Italic![/i]'); // Bold Italic!
```## Laravel integration
The integration into Laravel is really easy, and the method is the same for both Laravel 5.
Just open your ``app.php`` config file.In there you just add this to your providers array
``` php
PheRum\BBCode\BBCodeServiceProvider::class,
```And this to your facades array
``` php
'BBCode' => PheRum\BBCode\Facades\BBCode::class,
```The syntax is the same as if you would use it in vanilla PHP but with the ``BBCode::`` before the methods.
Here are some examples.
``` php
// Simple parsing
echo BBCode::parse('[b]Bold Text![/b]');// Limiting the parsers with the only method
echo BBCode::only('bold', 'italic')
->parse('[b][u]Bold[/u] [i]Italic[/i]![/b]'); // [u]Bold[/u] Italic!// Or the except method
echo BBCode::except('bold')
->parse('[b]Bold[/b] [i]Italic[/i]'); // [b]Bold[/b] Italic
```## Testing
``` bash
phpunit
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Credits
- [PheRum](https://github.com/pherum)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/pherum/laravel-bbcode.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/pherum/laravel-bbcode/master.svg?style=flat-square
[ico-styleci]: https://styleci.io/repos/65690597/shield
[ico-code-quality]: https://img.shields.io/scrutinizer/g/pherum/laravel-bbcode.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/pherum/laravel-bbcode.svg?style=flat-square[link-packagist]: https://packagist.org/packages/PheRum/laravel-bbcode
[link-travis]: https://travis-ci.org/PheRum/laravel-bbcode
[link-styleci]: https://styleci.io/repos/115532859
[link-code-quality]: https://scrutinizer-ci.com/g/PheRum/laravel-bbcode
[link-downloads]: https://packagist.org/packages/PheRum/laravel-bbcode
[link-author]: https://github.com/PheRum
[link-contributors]: ../../contributors