Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/#27 - convert html to txt file #28

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ $text = Html2Text\Html2Text::convert($html);

You can also include the supplied `html2text.php` and use `$text = convert_html_to_text($html);` instead.

## convert a html file to txt via php command directly.

suppose you have a html file named `test.html`, and you need convert it to txt file.

php convert.php test.html test.txt

## Tests

Some very basic tests are provided in the `tests/` directory. Run them with `composer install --dev && vendor/bin/phpunit`.
Expand Down
22 changes: 22 additions & 0 deletions convert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
require 'vendor/autoload.php';

var_dump($argv);

$html_file = $argv[1];
$text_file = $argv[2];

$html_handle = fopen($html_file, "r") or die("Unable to open file!");
$text_handle = fopen($text_file, "w");

$lines = "";
while (($line = fgets($html_handle)) !== false) {
$lines .= $line;
}
$txt = Html2Text\Html2Text::convert($lines);
fwrite($text_handle, $txt);

fclose($html_handle);
fclose($text_handle);

?>