XML; $rels = <<<'XML' XML; $document = <<<'XML' Contract Summary Report Reference: {{contract.reference}} Client Case Ref: {{client_case.client_ref}} Start Date: {{contract.start_date}} End Date: {{contract.end_date}} Description: {{contract.description}} Generated By: {{generation.user_name}} on {{generation.date}} XML; $zip = new ZipArchive; if ($zip->open($file, ZipArchive::CREATE) !== true) { fwrite(STDERR, "Cannot create docx file\n"); exit(1); } // Core parts $zip->addFromString('[Content_Types].xml', $contentTypes); $zip->addEmptyDir('_rels'); $zip->addFromString('_rels/.rels', $rels); $zip->addEmptyDir('word'); $zip->addFromString('word/document.xml', $document); $zip->close(); $hash = hash_file('sha256', $file); $size = filesize($file); echo json_encode([ 'file' => $file, 'size_bytes' => $size, 'sha256' => $hash, 'tokens_included' => [ 'contract.reference', 'client_case.client_ref', 'contract.start_date', 'contract.end_date', 'contract.description', 'generation.user_name', 'generation.date', ], ], JSON_PRETTY_PRINT).PHP_EOL;