PHP code example of crwlr / html-2-text
1. Go to this page and download the library: Download crwlr/html-2-text library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
crwlr / html-2-text example snippets
use Crwlr\Html2Text\Html2Text;
$html = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head><title>Example Website Title</title></head>
<body>
<script>console.log('test');</script>
<style>#app { background-color: #fff; }</style>
<article>
<h1>Article Headline</h1>
<h2>A Subheading</h2>
<p>Some text containing <a href="https://www.crwl.io">a link</a>.</p>
<ul>
<li>list item</li>
<li>another list item</li>
<li>and one more
<ul>
<li>second level
<ul>
<li>third level</li>
</ul>
</li>
</ul>
</li>
</ul>
<table>
<thead>
<tr><th>column 1</th><th>column 2</th><th>column 3</th></tr>
</thead>
<tbody>
<tr><td>value 1</td><td>value 2</td><td>value 3</td></tr>
<tr><td>value 1</td><td colspan="2">value 2 + 3</td></tr>
<tr><td colspan="2">value 1 and 2</td><td>value 3</td></tr>
<tr><td>value 1</td><td>value 2</td><td>value 3</td></tr>
</tbody>
</table>
</article>
</body>
</html>
HTML;
$text = Html2Text::convert($html);