Forum


Replies: 4   Views: 3539
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