Forum


Replies: 3   Views: 3516
Search and replace more different strings in same document
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by robertoblanco  · 22-05-2013 - 12:30

Hi,



What is the best way to search and replace more different strings in the same document?



So all #string1# should be replaced by #newstring1#, all #string2# by #newstring2#, and so on.



Should I do a search and replace per string and create a new document.



Next open the new document and then do the second search and replace? And repeat this as many times as necessary?



Or could I do this without generating each time new documents? I hope so ...



 



Regards,



Robert



 



 


Posted by erainferno  · 22-05-2013 - 19:51

Would it not be easier to use the replace variable?



$docx = new CreateDocx();

$docx->addTemplate('Template.docx');



for($index=1; $index <$numberofstrings;$index++){



          $docx->addTemplateVariable('string'.$index,'string'.$index);



}



$docx->createDocx('Files/Report');



 


Posted by jorgelj  · 23-05-2013 - 08:58

Hello,



You can use addTemplateVariable or replaceTemplateVariableByHTML to change placeholders in templates.



Regards.