PHP code example of daddyfrosty / laravel-bbcode-parser-zaym

1. Go to this page and download the library: Download daddyfrosty/laravel-bbcode-parser-zaym library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

daddyfrosty / laravel-bbcode-parser-zaym example snippets


use BBCode\Facades\BBCode;

echo BBCode::parse('[b]Text![/b]');
// The result is '<strong>Text!</strong>' 

echo BBCode::only(['bold', 'italic'])
        ->parse('[b][u]text[/u] [i]text[/i]![/b]');
/**
 * <strong>
 *  [u]Text[/u]
 *  <span style="font-style: italic;">text</span>
 * </strong> 
 */

echo BBCode::only('bold', 'italic')
        ->parse('[b][u]text[/u] [i]text[/i]![/b]');

echo BBCode::except('bold')
        ->parse('[b]text[/b] [i]text[/i]');
/**
 * [b]text[/b]
 * <span style="font-style: italic;">text</span> 
 */

# Case insensitive
echo BBCode::parse('[b]Bold[/b] [I]Italic![/I]', true); 

# or other way
echo BBCode::parseCaseInsensitive('[b]Bold[/b] [i]Italic[/i]');

BBCode::stripBBCodeTags('[b]Bold[/b] [i]Italic![/i]');



namespace App\Providers;

use BBCode\Facades\BBCode;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        BBCode::addTag(
            name:    'size',
            //                  $1      $2
            search: '/\[size\=([1-7])\](.*?)\[\/size\]/s',
            replace: '<span style="font-size: $1px;">$2</span>',
            content: '$2' // content param
        );
    }
}


BBCode::parse('[size=2]text[/size] [b]Example[/b]');
BBCode::except('size')->parse('[size=2]text[/size] [b]Example[/b]');
BBCode::only('size')->parse('[size=2]text[/size] [b]Example[/b]');
bash
php artisan vendor:publish --provider="Rwxrwx\BBCode\BBCodeServiceProvider" --tag="bbcodes-config"