I tried setting up a wordML with the following:
$wordML = '<w:r><w:fldChar w:fldCharType="begin"/></w:r>'; $wordML .= '<w:r><w:instrText xml:space="preserve">' . 'REF ' . $crossRefName . '</w:instrText></w:r>'; $wordML .= '<w:r><w:fldChar w:fldCharType="separate"/></w:r>'; $wordML .= '<w:r><w:t>' . $crossRefText . '</w:t></w:r>'; $wordML .= '<w:r><w:fldChar w:fldCharType="end"/></w:r>'; $bookmarkId = rand(9999999, 999999999); $wordML .= '<w:bookmarkStart w:id="' . $bookmarkId . '" w:name="_GoBack"/>'; $wordML .= '<w:bookmarkEnd w:id="' . $bookmarkId . '"/>';
And then:
$docx->replaceVariableByWordML(['myVar' => $wordML]);
But when opening the generated document I get the following error:
The Open XML file 'test.docx' cannot be opened because there are problems with the content or the file name might contain invalid characters. Unspecified error | Location: 2.
Where do you think the definition of my wordML is wrong?