So here is my code:
open(\'test.docx\') === TRUE) {
$xmlString = $zip->getFromName(\'word/document.xml\');
$x
Ok, I have used a class I found at phpclasses:
http://phpclasses.web4u.cz/package/6278-PHP-Edit-a-Zip-archive-in-pure-PHP-no-temporary-files.html
Here is the working code:
private function GenerateDocx($theTemplate, array $theReplacemenArray, $theOutputFile)
{
$aSearchArray = array();
foreach(range('A','Z') as $aLetter) {
$aSearchArray[] = str_repeat($aLetter, 5);
}
$aArrayCountDifference = count($aSearchArray) - count($theReplacemenArray);
$aSearchArray = array_slice($aSearchArray, 0, -$aArrayCountDifference);
require_once('tbszip.php');
$tbszip = new clsTbsZip();
$tbszip->Open($theTemplate);
$aXmlPath = 'word/document.xml';
if (true === $tbszip->FileExists($aXmlPath)) {
$aXmlString = $tbszip->FileRead($aXmlPath);
$aXmlString = str_replace($aSearchArray, $theReplacemenArray, $aXmlString);
if (1 != $tbszip->FileReplace($aXmlPath, $aXmlString)) {
throw new Exception('FileReplace() failed.');
}
$tbszip->Flush(TBSZIP_FILE, $theOutputFile);
$tbszip->Close();
}
}