PHP replaces variables in a Word document

I have a document with text that contains certain variables (e.g. the string $$ title $$). Now I want to open this word document in PHP and replace the line $$ title $$ with the line that I read from the database. The final step would be to save this word document and provide it to the user for download.

Replacing the line and starting the download is not a problem. But I do not know how I can get the content of a word in a variable in php, work with this variable, and then save it in a new word document.

Do any of you know a good PHP class that supports editing the contents of a Word document? (I'm fine with OpenXML formats, if necessary)

+3
source share
2 answers

Have you tried PHPWord ? I am using PHPExcel from the same site and it is a great library.

+6
source

Have you tried:

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

?

-2
source

Source: https://habr.com/ru/post/1768752/


All Articles