bicpi/html-converter
PHP library for converting HTML to plain text, ideal for generating text parts of HTML emails. Includes Simple (strip_tags), Lynx (best results, keeps links), Html2Text, and Chain converter to pick the first available backend.
bicpi/html-converter package is a lightweight, focused solution for converting HTML to plain text, which fits well in systems requiring text extraction (e.g., email processing, content sanitization, or analytics pipelines). It aligns with architectures where HTML parsing is a discrete, non-core requirement (e.g., microservices, background workers, or middleware layers).Mailable), and API response formatting (e.g., Response::make()) frequently generate or handle HTML. This package could streamline text extraction for:
HtmlPurger).symfony/dom or masterminds/html5.HtmlConverter::convert($html)).HtmlConverterFacade) for cleaner syntax.php artisan html:convert).filter_var($html, FILTER_VALIDATE_HTML)).DOMDocument.Str::of($html)->markdown()), or must the package handle raw input?DOMDocument) for edge cases?<table>, <pre>) that must be tested explicitly?config/app.php:
'providers' => [
Bicpi\HtmlConverter\HtmlConverterServiceProvider::class,
],
// app/Providers/AppServiceProvider.php
public function boot()
{
$this->app->make('HtmlConverter')->registerFacade();
}
Mailable events:
public function build()
{
return $this->markdown('emails.template')
->with(['text_version' => HtmlConverter::convert($this->htmlContent)]);
}
public function handle($request, Closure $next)
{
$response = $next($request);
if ($response->headers->get('Content-Type') === 'text/html') {
$response->setContent(HtmlConverter::convert($response->getContent()));
}
return $response;
}
public function saving(Model $model)
{
if (isset($model->html_content)) {
$model->text_content = HtmlConverter::convert($model->html_content);
}
}
DOMDocument for complex cases:
class HtmlConverterDecorator
{
public function convert($html)
{
try {
return HtmlConverter::convert($html);
} catch (Exception $e) {
return $this->fallbackToDom($html);
}
}
}
text columns (MySQL/VARCHAR(65535)).symfony/dom) by namespacing.bus:work) for high volume.$cacheKey = 'html_convert_'.md5($html);
return Cache::remember($cacheKey, 3600, fn() => HtmlConverter::convert($html));
filter_var($html, FILTER_VALIDATE_HTML) or wrap in a try-catch.HtmlConverter in tests).How can I help you explore Laravel packages today?