views:

26

answers:

2

Hello everyone

I have a word document that contains certain variables (for example the string $$title$$). Now I want to open this word document in PHP and replace the string $$title$$ with a string I read out of the database. Final step would be to save this word document and give it to the user for download.

Replacing the string and start the download is no problem. But I don't know how I can get the word content into a variable in php, work with that variable and then save it to a new word document.

Does any one of you know a good PHP class that provides support for editing the contents of a word document? (I'm fine with OpenXML formats if it has to be)

Thank you very much!

A: 

Did you try:

$doc = file_get_contents('mydoc.doc');
str_replace('TO_BE_REPLACED','NEW_TEXT', $doc);
file_put_contents('newdoc.doc');

?

Claudiu
I don't think this will work - doc files aren't plain text.
Did you at least try?
Claudiu
+1  A: 

Have you tried PHPWord? I've been using PHPExcel from the same site and it is great library.

dev-null-dweller
Exactly what I needed! Thank you very much!