s9e/text-formatter
PHP text formatting library with plugin support for BBCode, Markdown, HTML, and more. Includes predefined bundles, extensive documentation, and a JavaScript port for client-side preview and demos. Install via Composer and integrate customizable parsing/rendering.
use s9e\TextFormatter\Bundles\Forum as TextFormatter;
$text = '[quote="John Doe"]Star Wars spoiler: [spoiler]Snapes kills Dumbledore[/spoiler][/quote]';
$xml = TextFormatter::parse($text);
$html = TextFormatter::render($xml);
echo $html;
<blockquote><div><cite>John Doe wrote:</cite>Star Wars spoiler: <details class="spoiler"><summary class="spoiler-header" data-hide="Hide" data-show="Show">Spoiler </summary><div class="spoiler-content">Snapes kills Dumbledore</div></details></div></blockquote>
BBCodes enabled: b, center, code, color, email, i, img, list, li, *, media, quote, s, size, spoiler, u, url. Media BBCodes: Bandcamp, Dailymotion, Facebook, Indiegogo, Instagram, Kickstarter, Liveleak, Soundcloud, Twitch, Twitter, Vimeo, Vine, WSHH, YouTube.
Emoji are supported thanks to the free image set from Twemoji. Please consult their website for license terms.
The following emoticons are also supported as an alias to the corresponding emoji: :) :-) ;) ;-) :D :-D :( :-( :-* :P :-P :p :-p ;P ;-P ;p ;-p :? :-? :| :-| :o :lol:
use s9e\TextFormatter\Bundles\Forum as TextFormatter;
$text = '[quote="John Doe"]Star Wars spoiler :) [spoiler]Spocks kills Dumbledore[/spoiler][/quote]';
$xml = TextFormatter::parse($text);
$html = TextFormatter::render($xml, [
// Translatable strings used in [quote] and [spoiler]
'L_WROTE' => 'escribió:',
'L_HIDE' => 'Ocultar',
'L_SHOW' => 'Mostrar',
'L_SPOILER' => 'Spoiler'
]);
echo $html;
<blockquote><div><cite>John Doe escribió:</cite>Star Wars spoiler <img alt=":)" class="emoji" draggable="false" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f642.svg"> <details class="spoiler"><summary class="spoiler-header" data-hide="Ocultar" data-show="Mostrar">Spoiler </summary><div class="spoiler-content">Spocks kills Dumbledore</div></details></div></blockquote>
How can I help you explore Laravel packages today?