Forum


Replies: 4   Views: 3516
Bug in replacevariablebytext
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 smartbit  · 22-05-2015 - 07:51

Hi, Recently we've upgraded to phpdocx 4.6, now our clients are reporting this bug. They have multiple variables in their docx wich are replaced with user name and firstname like this. $person.name$ $person.firstname$ But the issue occurs when the variables are on the same line and the order of the variables in the array is reversed. $variables['persone.firstname'] = "John"; $variables['persone.name'] = "Doe"; I've debugged the variable2Text function in CreateDocxFromTemplate.inc like this (after $foundNodes = $dom->xpath($query): if($var == 'persoon.voornaam') { echo "foundNodes :: $var - $val".PHP_EOL; echo "$search >> $query" .PHP_EOL; var_dump($foundNodes); } if($var == 'persoon.naam') { echo "foundNodes :: $var - $val".PHP_EOL; echo "$search >> $query" .PHP_EOL; var_dump($foundNodes); die; } This is the output: foundNodes :: person.firstname - John $person.firstname$ >> //w:t[text()[contains(., "$person.firstname$")]] array(1) { [0] => class SimpleXMLElement#293 (1) { public ${0} => string(21) "$ $peroon.firstname$ " } } foundNodes :: person.name - Doe $person.name$ >> //w:t[text()[contains(., "$person.name$")]] array(0) { } As you can see the first time it replaces "$ $person.firstname$" So it leaves $person.name John in the dom and doesn't replace $person.name$ anymore Do you have any solutions to fix the query? $query = '//w:t[text()[contains(., "' . $search . '")]]'; Thx

Posted by smartbit  · 22-05-2015 - 08:00

I've tried it without replacing the firstname and only the name. And this is de debug info: foundNodes :: person.name - Bouckaert $persoon.naam$ >> //w:t[text()[contains(., "$person.name$")]] array(1) { [0] => class SimpleXMLElement#293 (1) { public ${0} => string(16) "$person.name$ $" } } As you see it finds "$person.name$ $" it seems it doesn't recognize the space between the two variables.

Posted by admin  · 22-05-2015 - 13:27

Hello, Please send the DOCX to contact[at]phpdocx.com. We have done some quick tests and eveything looks correct, so we need to check the document. Regards.

Posted by smi  · 19-06-2015 - 20:45

I have the same problem with a very simple template and the order of the variables is the same as in the array. I have tried the space symbol in between; but it has no effect. My coder claims this is because I am using WORD 2007, since she says it doesn't happen on her computer. Even if that is the issue, many of my clients also are on WORD 2007 -- or earlier, What I am selling is a product on good English. This is, therefore, a major issue for me. I certainly hope you can solve it.

Posted by admin  · 20-06-2015 - 07:47

Hello, As requested previously, please send a DOCX sample to contact[at]phpdocx.com. We haven't received any DOCX that illustrate the issue yet; and the test we have done are correct. We do all tests with Word 2007, Word 2010, LibreOffice, OpenOffice... Regards.