- Saved searches
- Use saved searches to filter your results more quickly
- Docxpresso/HTML2TEXT
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- mtibben/html2text
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- License
- soundasleep/html2text
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- License
- pH-7/Html2Text
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A PHP package to convert HTML into plain text
Docxpresso/HTML2TEXT
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
HTML to Plain Text Converter
HTML2TEXT is a single class PHP package that converts HTML into plain text.
It uses DOM methods rather than regular expressions and although it works out of the box it can be easily further customized to suit any particular need.
You can visit the official page in Docxpresso.
The recommended way to install HTML2TEXT is through Composer.
# Install Composer curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version of HTML2TEXT:
php composer.phar require docxpresso/html2text
After installing, you need to require Composer’s autoloader:
require 'vendor/autoload.php';
You can then later update HTML2TEXT using composer:
The use of HTML2TEXT is extremely simple:
require __DIR__ . '/../vendor/autoload.php'; use Docxpresso\HTML2TEXT as Parser; $html = 'A simple paragraph.
'; $parser = new Parser\HTML2TEXT($html); echo $parser->plainText();
You can override some of the default values by including an options array whenever you invoke the HTML2TEXT class. The following options are available:
- bold: a string of chars that will wrap text in b or strong tags. The default value is an empty string.
- cellSeparator: a string of chars used to separate content between contiguous cells in a row. Default value is » || » (\t may be also a sensible choice)
- images: if set to true the alt value associated to the image will be printed like [img: alt value]. Default value is true.
- italics: a string of chars that will wrap text in i or em tags. The default value is an empty string.
- newLine: if set it will replace the default value (\n\r) for titles and paragraphs.
- tab: a string of chars that will be used like a «tab». The default value is » » (\t may be another standard option)
- titles: it can be «underline» (default), «uppercase» or «none».
About
A PHP package to convert HTML into plain text
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
PHP library to convert HTML to formatted plain text
mtibben/html2text
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
A PHP library for converting HTML to formatted plain text.
composer require html2text/html2text
$html = new \Html2Text\Html2Text('Hello, "world"'); echo $html->getText(); // Hello, "WORLD"
This library started life on the blog of Jon Abernathy http://www.chuggnutt.com/html2text
A number of projects picked up the library and started using it — among those was RoundCube mail. They made a number of updates to it over time to suit their webmail client.
Now it has been extracted as a standalone library. Hopefully it can be of use to others.
About
PHP library to convert HTML to formatted plain text
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A PHP component to convert HTML into a plain text format
License
soundasleep/html2text
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
html2text is a very simple script that uses DOM methods to convert HTML into a format similar to what would be rendered by a browser — perfect for places where you need a quick text representation. For example:
html> title>Ignored Titletitle> body> h1>Hello, World!h1> p>This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly. p>Even mismatched tags.p> div>A divdiv> div>Another divdiv> div>A divdiv>within a divdiv>div> a href pl-s">http://foo.com">A linka> body> html>
Hello, World! This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly. Even mismatched tags. A div Another div A div within a div [A link](http://foo.com)
You can use Composer to add the package to your project:
< "require": < "soundasleep/html2text": "~1.1" > >
And then use it quite simply:
$text = \Soundasleep\Html2Text::convert($html);
You can also include the supplied html2text.php and use $text = convert_html_to_text($html); instead.
Option | Default | Description |
---|---|---|
ignore_errors | false | Set to true to ignore any XML parsing errors. |
drop_links | false | Set to true to not render links as [http://foo.com](My Link) , but rather just My Link . |
char_set | ‘auto’ | Specify a specific character set. Pass multiple character sets (comma separated) to detect encoding, default is ASCII,UTF-8 |
Pass along options as a second argument to convert , for example:
$options = array( 'ignore_errors' => true, // other options go here ); $text = \Soundasleep\Html2Text::convert($html, $options);
Some very basic tests are provided in the tests/ directory. Run them with composer install && vendor/bin/phpunit .
Class ‘DOMDocument’ not found
You need to install the PHP XML extension for your PHP version. e.g. apt-get install php7.4-xml
html2text is licensed under MIT, making it suitable for both Eclipse and GPL projects.
Also see html2text_ruby, a Ruby implementation.
About
A PHP component to convert HTML into a plain text format
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A very simple (but efficient) «HTML to plain text» converter ✍️
License
pH-7/Html2Text
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
A simple lightweight «HTML to Plain Text» converter 🪄
Simple. Clean. Efficient. Just what you need to convert HTML code into plain text 🧹
composer require ph-7/html-to-text
If you don’t already use composer in your project, include Composer’s autoload as shown below in your main PHP index file of your project.
require __DIR__ . '/vendor/autoload.php';
use PH7\HtmlToText\Convert; $htmlCode = ''; $this->html2Text = new Convert($htmlCode); $plainText = $this->html2Text->getText(); echo $plainText;Some random paragraphs.
Pierre-Henry Soria. A super passionate, zen & pragmatic software engineer 😊 Cheese & dark chocolate lover! 🧀 🍫 😋
️ ☕️ Are you enjoying it. You could offer me a coffee if you wish 😋
HTML to Text is generously distributed under MIT 🎉 Enjoy!
About
A very simple (but efficient) «HTML to plain text» converter ✍️