Skip to content

Commit 9d6b2ff

Browse files
committed
Update src/PHPWord/Template.php
This function returns array of all variables in template. Test code: $PHPWord = new PHPWord(); $document = $PHPWord->loadTemplate('Template.docx'); var_dump($document->getVariables());
1 parent 4f457c9 commit 9d6b2ff

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/PHPWord/Template.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ public function setValue($search, $replace) {
9191

9292
$this->_documentXML = str_replace($search, $replace, $this->_documentXML);
9393
}
94-
94+
/**
95+
* Returns array of all variables in template
96+
*/
97+
public function getVariables()
98+
{
99+
preg_match_all('/\$\{(.*?)}/i', $this->_documentXML, $matches);
100+
return $matches[1];
101+
}
95102
/**
96103
* Save Template
97104
*

0 commit comments

Comments
 (0)