php mail merge docx document

Solutions on MaxInterview for php mail merge docx document by the best coders in the world

showing results for - "php mail merge docx document"
Juan Esteban
03 Jun 2019
1<?php
2
3include_once('tbszip.php');
4
5$zip = new clsTbsZip();
6
7// Open the first document
8$zip->Open('doc1.docx');
9$content1 = $zip->FileRead('word/document.xml');
10$zip->Close();
11
12// Extract the content of the first document
13$p = strpos($content1, '<w:body');
14if ($p===false) exit("Tag <w:body> not found in document 1.");
15$p = strpos($content1, '>', $p);
16$content1 = substr($content1, $p+1);
17$p = strpos($content1, '</w:body>');
18if ($p===false) exit("Tag </w:body> not found in document 1.");
19$content1 = substr($content1, 0, $p);
20
21// Insert into the second document
22$zip->Open('doc2.docx');
23$content2 = $zip->FileRead('word/document.xml');
24$p = strpos($content2, '</w:body>');
25if ($p===false) exit("Tag </w:body> not found in document 2.");
26$content2 = substr_replace($content2, $content1, $p, 0);
27$zip->FileReplace('word/document.xml', $content2, TBSZIP_STRING);
28
29// Save the merge into a third file
30$zip->Flush(TBSZIP_FILE, 'merge.docx');
31