Good morning my friends!
I'm posting here a code that I created to use the while to repeat part of the document between two tags. Sorry for my English, I'm using a translator
Note # 1: The beginning and the size of substr I made based on the XML document, taking care not to cut through the xml tags. This still needs to be improved so that does not depend on changes in this case funcioanaria with a portion of the document, but can be pulled inside the function by placing the counter. eg clonePart ('[tags]', '[tage]', $ num, 120.14). If someone can help me improve this code so grateful that it becomes automated.
Note # 2: This code will create a numbering in all variables according to the number of copies, so you can access all the variables of all copies, see the example after the code.
IMPORTANT: This code is not yet optimized, but it works. He was inspired by the code cloneRows made by Jeroen Moors (http://jeroen.is/phpword-templates-with-repeating-rows/) that can even be used together as I myself. Any doubts do whatever possible to help!
Add to Template.php
```
public function clonePart($start, $end, $numberOfClones){
$string = $this->_documentXML;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
$part = substr($string,$ini,$len);
$part = substr($part,18,(strlen($part)-237)); //Note #1
$partJN = '';
for ($i = 1; $i <= $numberOfClones; $i++) {
$partJN .= str_replace('OT}','_'.$i.'}',$part); //Note #2, this is used to put numbers to variables, OT is a anchor, exemple: ${nameOT} turn to ${name_1} ${name_2}...
}
$this->_documentXML = str_replace('[STApart]','',$this->_documentXML); //Erase Tag
$this->_documentXML = str_replace('[ENDpart]','',$this->_documentXML); //Erase Tag
$this->_documentXML = str_replace($part,'',$this->_documentXML); //Erase Original Part Because doenst have count
$partJN = utf8_decode($partJN);
$this->setValue('reportone',$partJN); //Place Content to a Variable (in this case ${reportone}
}
```
Mysql use exemple:
```
$NUM = num_rows;
clonePart('[mystarttag]', '[myendtag]', $NUM);
$i=1;
while($FET){
$doc->SetValue('name_'.$i,$FET['name']);
$i++;
}
```