Sample code for 30+ languages & platforms
Perl

Convert HTML to Plain Text

Demonstrates how to convert HTML to plain text.

Chilkat Perl Downloads

Perl
use chilkat();

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

$h2t = chilkat::CkHtmlToText->new();

$html = $h2t->readFileToString("c:/temp/test.html","utf-8");
if ($h2t->get_LastMethodSuccess() == 0) {
    print $h2t->lastErrorText() . "\r\n";
    exit;
}

$plainText = $h2t->toText($html);
if ($h2t->get_LastMethodSuccess() == 0) {
    print $h2t->lastErrorText() . "\r\n";
    exit;
}

print $plainText . "\r\n";