Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 402 | All time: 6,556 This week: 78 |
Version | License | PHP version | Categories | |||
html2text 1.0.18 | GNU General Publi... | 5 | HTML, PHP 5, Text processing |
Collaborate with this project | Author | |
html2text - github.com Description This class can parse HTML and extract text contained in it. Innovation Award |
Convert HTML to formatted plain text, e.g. for text mails.
The recommended installation way is through Composer.
$ composer require voku/html2text
$html = new \voku\Html2Text\Html2Text('Hello, "<b>world</b>"');
echo $html->getText(); // Hello, "WORLD"
Each element (h1, li, div, etc) can have the following options:
For example:
$html = '<h1>Should have "AAA" changed to BBB</h1><ul><li>• Custom bullet should be removed</li></ul><img alt="The Linux Tux" src="tux.png" />';
$expected = 'SHOULD HAVE "BBB" CHANGED TO BBB' . "\n\n" . '- Custom bullet should be removed |' . "\n\n" . '[IMAGE]: "The Linux Tux"';
$html2text = new Html2Text(
$html,
array(
'width' => 0,
'elements' => array(
'h1' => array(
'case' => Html2Text::OPTION_UPPERCASE,
'replace' => array('AAA', 'BBB')),
'li' => array(
'case' => Html2Text::OPTION_NONE,
'replace' => array('•', ''),
'prepend' => "- ",
'append' => " |",
),
),
)
);
$html2text->setPrefixForImages('[IMAGE]: ');
$html2text->setPrefixForLinks('[LINKS]: ');
$html2text->getText(); // === $expected
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 this is a extend fork of the original Html2Text.
For support and donations please visit Github | Issues | PayPal | Patreon.
For status updates and release announcements please visit Releases | Twitter | Patreon.
For professional support please contact me.
Files (70) |
File | Role | Description | ||
---|---|---|---|---|
src (1 file) | ||||
tests (26 files, 1 directory) | ||||
.editorconfig | Data | Auxiliary data | ||
.scrutinizer.yml | Data | Auxiliary data | ||
.styleci.yml | Data | Auxiliary data | ||
.travis.yml | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE.md | Lic. | License text | ||
phpcs.php_cs | Example | Example script | ||
phpstan.neon | Data | Auxiliary data | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files (70) | / | tests |
File | Role | Description | ||
---|---|---|---|---|
fixtures (32 files) | ||||
BasicTest.php | Class | Class source | ||
BlankSpacesTest.php | Class | Class source | ||
BlockquoteTest.php | Class | Class source | ||
bootstrap.php | Aux. | Auxiliary script | ||
ConstructorTest.php | Class | Class source | ||
DefinitionListTest.php | Class | Class source | ||
ElementsTest.php | Class | Class source | ||
HeadingsTest.php | Class | Class source | ||
HtmlCharsTest.php | Class | Class source | ||
ImageTest.php | Class | Class source | ||
LinkTest.php | Class | Class source | ||
ListItemsTest.php | Class | Class source | ||
ListTest.php | Class | Class source | ||
MailTest.php | Class | Class source | ||
NewlineSpaceTest.php | Class | Class source | ||
NewlineTabBreakTest.php | Class | Class source | ||
ParagraphBreakTest.php | Class | Class source | ||
PreTest.php | Class | Class source | ||
PrintTest.php | Class | Class source | ||
SearchReplaceTest.php | Class | Class source | ||
SpaceTest.php | Class | Class source | ||
SpanTest.php | Class | Class source | ||
StrToUpperTest.php | Class | Class source | ||
TableTest.php | Class | Class source | ||
UnderscoresTest.php | Class | Class source | ||
UppercaseTest.php | Class | Class source |
Files (70) | / | tests | / | fixtures |
File | Role | Description |
---|---|---|
code.html | Doc. | Documentation |
code.txt | Doc. | Documentation |
dl_dt_dd.html | Doc. | Documentation |
dl_dt_dd.txt | Doc. | Documentation |
msoffice.html | Doc. | Documentation |
msoffice.txt | Doc. | Documentation |
nbsp.html | Doc. | Documentation |
nbsp.txt | Doc. | Documentation |
non-breaking-spaces.html | Doc. | Documentation |
non-breaking-spaces.txt | Doc. | Documentation |
table.html | Doc. | Documentation |
table.txt | Doc. | Documentation |
test10Html.html | Doc. | Documentation |
test10Html.txt | Doc. | Documentation |
test1Html.html | Doc. | Documentation |
test1Html.txt | Doc. | Documentation |
test2Html.html | Doc. | Documentation |
test2Html.txt | Doc. | Documentation |
test3Html.html | Doc. | Documentation |
test3Html.txt | Doc. | Documentation |
test4Html.html | Doc. | Documentation |
test4Html.txt | Doc. | Documentation |
test5Html.html | Doc. | Documentation |
test5Html.txt | Doc. | Documentation |
test6Html.html | Doc. | Documentation |
test6Html.txt | Doc. | Documentation |
test7Html.html | Doc. | Documentation |
test7Html.txt | Doc. | Documentation |
test8Html.html | Doc. | Documentation |
test8Html.txt | Doc. | Documentation |
test9Html.html | Doc. | Documentation |
test9Html.txt | Doc. | Documentation |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.