1/*
2 * https://stackoverflow.com/a/65703321/13779574
3 * https://github.com/PHPOffice/PHPWord
4 * I also did this problem in phpword using the following code
5 */
6 if(!file_exists('file/word.docx')){
7 $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('demo.docx');
8 $templateProcessor->setValue('name', 'Akbarali');
9 $templateProcessor->setValue('time','13.02.2021');
10 $templateProcessor->setValue('month', 'January');
11 $templateProcessor->setValue('state','Uzbekistan');
12 $templateProcessor->saveAs('file/word.docx');
13}
14/*
15 * This will change the words in the demo.docx file.
16 * The new file is then saved in the word.docx file folder.
17 * You can define variables in the form of $ {name} in the demo word file.
18 * That is, ${name}, ${time}, ${month} and ${state}
19 */