Sample code for 30+ languages & platforms
PHP Extension

Convert HTML to Plain Text

Demonstrates how to convert HTML to plain text.

Chilkat PHP Extension Downloads

PHP Extension
<?php

include("chilkat.php");

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

$h2t = new CkHtmlToText();

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

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

print $plainText . "\n";

?>