PHP Classes

PHP DOCX to Text: Extract text from Microsoft Word DOCX files

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2021-11-03 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 102 All time: 9,521 This week: 225Up
Version License PHP version Categories
docxtotext 1.0.0GNU General Publi...5PHP 5, Files and Folders, Text proces...
Description Author

This class can extract text from Microsoft Word DOCX files.

It can take the path of a Microsoft Word file in DOCX format and extract its contents to save the text it contains, including the list and paragraph numbering along with footnotes and endnotes and their reference numbers.

The class returns document text as an array with one element per paragraph.

Picture of Timothy Edwards
  Performance   Level  
Name: Timothy Edwards <contact>
Classes: 4 packages by
Country: United Kingdom
Age: ???
All time rank: 3707161 in United Kingdom
Week rank: 20 Up3 in United Kingdom Up
Innovation award
Innovation award
Nominee: 2x


A php class to extract all the text from a Word DOCX document and to output it as a text array


This php class will take a DOCX type Word document and extract all the text from it. The text will include all list and paragraph numbering and also footnotes and endnotes together with their reference numbers. The text will outputted as an array, one array element per paragraph. This will make it easy to search or manipulate the text or to save it to a database. For convenience the first element [0] of the array contains the number of text array elements and the length of the longest element in the format 'Number:Length'. In normal mode the class produces no output to the screen.

A demonstration file 'textdemo.php' is included. This expects the Word docx file to be called 'sample.docx'. The demonstration file will display on screen the resultant text array, giving the number of text elements, the length of the longest one and then all the text extracted from the document along with its array element number.


Include the class in your php script


Normal mode to save all the the text to an array (no output to screen)

$rt = new WordTEXT(false); or $rt = new WordTEXT();

Debug mode to display on screen the associated DOCX XML files and the text extracted from the document

$rt = new WordTEXT(true);

Set output encoding (Default is ISO-8859-1)

Will alter the encoding of the resultant text - eg. 'UTF-8', 'windows-1252', etc.

$rt = new WordTEXT(false, 'desired encoding');

Read docx file and output all the text as an array

$text = $rt->readDocument('FILENAME');
  Files folder image Files  
File Role Description
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Doc. Documentation
Accessible without login Plain text file textdemo.php Example Example script
Plain text file wordtext.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,521
This week:225Up
For more information send a message to info at phpclasses dot org.