承接 daddyfrosty/laravel-bbcode-parser-zaym 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

daddyfrosty/laravel-bbcode-parser-zaym

最新稳定版本:1.0.1

Composer 安装命令:

composer require daddyfrosty/laravel-bbcode-parser-zaym

包简介

Parse your bbcode easy with this library.

README 文档

README

What is BBCode

BBCode on wikipedia

How does it work?

This package parse bbcode tags to html.

Install

Via Composer

composer require daddyfrosty/laravel-bbcode-parser-zaym

Usage With Laravel

To parse some text it's as easy as this!

use BBCode\Facades\BBCode;

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

Parse only selected tags.

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]');

Parse all except one or more tags.

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

Case sensitive & insensitive

By default, the parser is case sensitive.

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

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

Strip or remove all bbcode tags

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

Laravel Blade

@bb('[b]Bold[/b] [i]Italic[/i]') 
{{-- <strong>Bold</strong> <em>Italic</em> --}}

@bbexcept('bold', '[b]Bold[/b] [i]Italic[/i]') 
{{-- [b]Bold[/b] <em>Italic</em> --}}

@bbonly('bold', '[b]Bold[/b] [i]Italic[/i]')
{{-- <strong>Bold</strong> [i]Italic[/i] --}}

Extending or editing BBCode tags

Can add custom bbcode tags inside config file

php artisan vendor:publish --provider="Rwxrwx\BBCode\BBCodeServiceProvider" --tag="bbcodes-config"

Or you can add using method

<?php

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
        );
    }
}

Using

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]');

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-29