Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Html Converter

Html Converter Laravel Package

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.

View on GitHub
Deep Wiki
Context7

HTML-to-Text converter library

Frequently asked questions about Html Converter
How do I integrate **bicpi/html-converter** into a Laravel project?
Register the package as a service provider in `config/app.php` and optionally create a facade for cleaner syntax. Use the `ChainConverter` to prioritize backends like Lynx for best results. Example: `$converter = new ChainConverter(); $converter->addConverter(new LynxConverter());`
Which Laravel versions does this package support?
The package is PHP 7.4+ compatible and works with Laravel 8.x, 9.x, and 10.x. No Laravel-specific dependencies mean it’s framework-agnostic but fully interoperable with modern Laravel apps.
Can I use this for converting HTML emails in Laravel Mailables?
Yes. Hook into Laravel’s `Mailable` class to generate plain-text versions of HTML emails. Example: `$this->with(['text_version' => HtmlConverter::convert($this->htmlContent)])` in your `build()` method.
What’s the best converter backend for preserving links in emails?
Use the `LynxConverter`—it mimics Lynx’s text browser output, preserving links as references. Requires the `lynx` system package (`apt-get install lynx` on Ubuntu). Fall back to `SimpleConverter` if Lynx isn’t available.
How do I handle malformed HTML (e.g., unclosed tags) in production?
Preprocess HTML with `filter_var($html, FILTER_VALIDATE_HTML)` or use Laravel’s `Str::of($html)->markdown()` for basic sanitization. For edge cases, chain `LynxConverter` with `SimpleConverter` as a fallback.
Is this package suitable for high-volume API responses (e.g., 10K+ requests/day)?
Yes, but benchmark with large payloads. The `SimpleConverter` is fastest (uses `strip_tags()`), while `LynxConverter` adds minimal overhead. Cache converted results if reprocessing is common.
Can I test this package with PHPUnit in Laravel?
Absolutely. Mock HTML inputs (e.g., `<h1>Test</h1>`) and assert outputs with `assertEquals()`. Example: `$converter = new SimpleConverter(); $this->assertEquals('Test', $converter->convert('<h1>Test</h1>'));`
What are the alternatives to **bicpi/html-converter** for Laravel?
For lightweight needs, this package is ideal. For advanced HTML parsing (CSS/JS), consider `symfony/dom` or `masterminds/html5`. For email-specific needs, Laravel’s built-in `Mailable` text templates may suffice.
How do I convert HTML fields in Eloquent models before saving?
Use a model observer or accessor. Example: `public function getTextContentAttribute() { return HtmlConverter::convert($this->html_content); }` or in an observer: `$model->text_content = HtmlConverter::convert($model->html_content);`.
Does this package support converting tables or complex layouts?
Basic support exists, but results vary by backend. `LynxConverter` handles tables decently, while `SimpleConverter` flattens them. For precise control, preprocess HTML with DOMDocument or use `masterminds/html5` for advanced layouts.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle