Require this package with composer using the following command:
composer require irebega/docx-replacer
This code will replace $search to $replace in $pathToDocx file
$docx = new IRebega\Docx($pathToDocx);
$docx->replaceText($search, $replace);
This code will replace every key in $fromToArray to his corresponding value and apply it to $pathToDocx file
$docx = new IRebega\Docx($pathToDocx);
$fromToArray = array('key1' => 'value1', 'key2' => 'value2', ...);
$docx->replaceTexts($fromToArray);
This code will replace text $search to image that are located in $path in $pathToDocx file
$docx = new IRebega\Docx($pathToDocx);
$docx->replaceTextToImage($search, $path);
PHP .docx replacer is open-sourced software licensed under the MIT license