Hi guys,

Im quite new to php. Currently, im trying to convert my php to word and been googling for a long time about this. Anyone know how to convert php to word (free). For your information, im using Suse Linux as my server. Really need some suggestion for my problem :D


4 Weeks
Discussion Span
Last Post by diafol
Featured Replies

As diafol said - do you just want to convert PHP output to Word documents? That is easy (assuming you know php well enough). To convert abstract data to Word is an entire other kettle of fish! In any case, you need to show us what your data is and what problems your are having before we can contribute more to your solution.


diafol/rubberman, yup i want to convert php output to word documents. i already tried phpword from github but im stuck when installing this requirement :

Zend\Escaper component
Zend\Stdlib component
Zend\Validator component

the tutorial from https://framework.zend.com/downloads said its can be done by installing composer. i tried the command via composer but the error as the attachment i included. zend.jpg


Go to
location and execute
mv composer.phar /usr/local/bin/composer
Then you can use composer further. Double check what docs say.

Edited by Tpojka


Thanks for your response/information diafol and tpojka, i already followed those command and i think its work since no error occur when i run it :D ~~thank for those ~~
Next, im trying used the code from example and and its become blank. Then i realise there's a lil confuse about this line :

// Creating the new document...
$phpWord = new \PhpOffice\PhpWord\PhpWord();

Here's the full code :

require_once 'bootstrap.php';

// Creating the new document...
$phpWord = new \PhpOffice\PhpWord\PhpWord();

/* Note: any element you append to a document must reside inside of a Section. */

// Adding an empty Section to the document...
$section = $phpWord->addSection();
// Adding Text element to the Section having font styled by default...
    '"Learn from yesterday, live for today, hope for tomorrow. '
        . 'The important thing is not to stop questioning." '
        . '(Albert Einstein)'

 * Note: it's possible to customize font style of the Text element you add in three ways:
 * - inline;
 * - using named font style (new font style object will be implicitly created);
 * - using explicitly created font style object.

// Adding Text element with font customized inline...
    '"Great achievement is usually born of great sacrifice, '
        . 'and is never the result of selfishness." '
        . '(Napoleon Hill)',
    array('name' => 'Tahoma', 'size' => 10)

// Adding Text element with font customized using named font style...
$fontStyleName = 'oneUserDefinedStyle';
    array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
    '"The greatest accomplishment is not in never falling, '
        . 'but in rising again after you fall." '
        . '(Vince Lombardi)',

// Adding Text element with font customized using explicitly created font style object...
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)');

// Saving the document as OOXML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');

// Saving the document as ODF file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');

// Saving the document as HTML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');

/* Note: we skip RTF, because it's not XML-based and requires a different example. */
/* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */

My next question is, why the code have PhpOffice before the PhpWord's folder? Is there anything i should install or should i create a folder named PhpOffice. I just assume the path is the problem.


Im try looking for this PHPOffice folder in my server but none of this folder found. :D
is there something wrong with my composer installation? Is this PHPOffice folder will exist if i successfully install the composer or should i create this PHPOffice folder? Im so confuse right now.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.