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

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

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

ammarkannas/laravel-bbcode-parser

最新稳定版本:v1.0.1

Composer 安装命令:

composer require ammarkannas/laravel-bbcode-parser

包简介

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 ammarkannas/laravel-bbcode-parser

Usage With Laravel

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

use Ammar\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 Ammar\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.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固