I know there are librarys such as PHPWord or PHPDocx, but PHPWord is inefficient and can lose variables and PHPDocx is a paid library so I can't use that. Is there some type of field in word which remains constant and is easily legible which I can use for my replacement fields in my php script? I've tried str_replace with tags like ${TAG1} but sometimes these characters get seperated by word tags and therefore the script doesn't find them.. Any help?
Asked
Active
Viewed 1,099 times
1 Answers
1
You could use bookmarks. If you create a bookmark with the name "title" the document.xml will contain these tags:
<w:bookmarkStart w:id="0" w:name="title"/><w:r><w:t>World</w:t></w:r><w:bookmarkEnd w:id="0"/>
-
How would I go about changing the content of the bookmark from the name though? I'm not very familiar with XML and this doesn't look like correct XML to me. – PwnageAtPwn Aug 17 '12 at 11:39
-
It is just a part of a word xml. You search for the bookmark, remove all nodes between w:bookmarkStart and w:bookmarkEnd and add you content as sibbling just after the bookmark. Play arround with word to find out how to format text with word xml. – Oliver A. Aug 17 '12 at 11:50
-
I've tried to get the word bookmarks by doing $xmlDoc->getElementsByTagName( "w:bookmarkStart" ); and using a foreach to loop through all of the ids by getAttribute('w:id'); but I get no result, am I doing something wrong? – PwnageAtPwn Aug 17 '12 at 11:57
-
Nevermind, I found a solution using NodeValues. – PwnageAtPwn Aug 17 '12 at 12:21
-
1Sorry I did no xml editng for some time. The problem was that u used the "w:" prefix you have to use " $xmlDoc->getElementsByTagName( "bookmarkStart"); WITHOIUT the prefix – Oliver A. Aug 17 '12 at 12:29