Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Class to extract text or HTML from file
* File to enable reading text or HTML from a file
class FiletoText
private $path, $extension;
function __construct($filepath, $fileextension) {
$this->path = $filepath; // absolute path to the file do whatever conversions you need to do here
$this->extension = $fileextension;
* Return the text or HTML from the file
* @return String
function getText() {
switch ($this->extension) {
case "doc";
case "docx";
case "rtf";
$mailMerge = new Zend_Service_LiveDocx_MailMerge();
$mailMerge->setUsername('username')->setPassword('password'); // credetnials
$mailMerge->assign(null); // must be called as of phpLiveDocx 1.2
return $mailMerge->retrieveDocument('html');
case "pdf";
$a = new PDF2Text();
$a->setFilename($this->path); //grab the test file at
return $a->output();
case "xls";
case "xlsx";
$html_writer = new PHPExcel_Writer_HTML(PHPExcel_IOFactory::load($this->path));
$tmp_file_name = time().".htm";
return file_get_contents($tmp_file_name);
return "";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.