IMPROVED : Advanced string replace in setValue for Template
This commit is contained in:
parent
38a15e5da5
commit
049c89d079
|
|
@ -84,6 +84,14 @@ class PHPWord_Template {
|
||||||
* @param mixed $replace
|
* @param mixed $replace
|
||||||
*/
|
*/
|
||||||
public function setValue($search, $replace) {
|
public function setValue($search, $replace) {
|
||||||
|
$pattern = '|\$\{([^\}]+)\}|U';
|
||||||
|
preg_match_all($pattern, $this->_documentXML, $matches);
|
||||||
|
foreach ($matches[0] as $value) {
|
||||||
|
$valueCleaned = preg_replace('/<[^>]+>/', '', $value);
|
||||||
|
$valueCleaned = preg_replace('/<\/[^>]+>/', '', $valueCleaned);
|
||||||
|
$this->_documentXML = str_replace($value, $valueCleaned, $this->_documentXML);
|
||||||
|
}
|
||||||
|
|
||||||
if(substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
|
if(substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
|
||||||
$search = '${'.$search.'}';
|
$search = '${'.$search.'}';
|
||||||
}
|
}
|
||||||
|
|
@ -96,6 +104,7 @@ class PHPWord_Template {
|
||||||
|
|
||||||
$this->_documentXML = str_replace($search, $replace, $this->_documentXML);
|
$this->_documentXML = str_replace($search, $replace, $this->_documentXML);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns array of all variables in template
|
* Returns array of all variables in template
|
||||||
*/
|
*/
|
||||||
|
|
@ -104,6 +113,7 @@ class PHPWord_Template {
|
||||||
preg_match_all('/\$\{(.*?)}/i', $this->_documentXML, $matches);
|
preg_match_all('/\$\{(.*?)}/i', $this->_documentXML, $matches);
|
||||||
return $matches[1];
|
return $matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save Template
|
* Save Template
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -34,3 +34,4 @@ Fixed in branch for release 0.7 :
|
||||||
- General: (Progi1984) - Basic CI with Travis
|
- General: (Progi1984) - Basic CI with Travis
|
||||||
- General: (Progi1984) - Added PHPWord_Exception and exception when could not copy the template
|
- General: (Progi1984) - Added PHPWord_Exception and exception when could not copy the template
|
||||||
- General: (Progi1984) - IMPROVED : Moved examples out of Classes directory
|
- General: (Progi1984) - IMPROVED : Moved examples out of Classes directory
|
||||||
|
- General: (Esmeraldo) CP-49 - IMPROVED : Advanced string replace in setValue for Template
|
||||||
Loading…
Reference in New Issue