Convert HTML to Text with PHP-4


This example is part of the project titled HTML Parser for PHP-4. It's a class named Html2Text which converts HTML to ASCII text, while attempting to preserve page formatting.


Tested with PHP 4.0.4. It should work with PHP 4.0.3+.


The latest version is available at SourceForge's download area for this project.


Perhaps the most relevant limitations of the latest version of this simple tool are that it ignores tables and that it does not center.


The HTML Parser for PHP-4 and this example were written by Jose Solorzano of Starnetsys, LLC. (If you need a website or program developed professionally, affordably, and on time, be sure to contact

Usage Tips

You only need to copy src/ and src/ to a location in your codebase where you'd like to be able to include them. The PHP file that uses this conversion tool could look like this:

  include ("");

  $htmlText = "... HTML text here ...";
  $asciiText = new Html2Text ($htmlText, 15); // 15 columns maximum
  $text = $htmlToText->convert();
  echo "Converted to: " . $text;



  • For feature requests, please use SourceForge's Feature Request Tracker.
  • To report a bug, use SourceForge's Bug Tracking System.
  • For questions, use SourceForge's Forums for this project.
  • If you want to be added to this project as a developer, send me a sample or a sketch of the code you plan to add. Logo