Skip to content

XML escape for templateprocessor setValue #746

Closed
@evotodi

Description

@evotodi

PHPWord Version 0.12.0
Setting a value with an & in the string will cause Word to think the document is corrupt.

Add the below function to TemplateProcessor.php:
/**
* @param string $string
* @return string
*/
private function xmlEscape($string) {
return str_replace(array('&', '<', '>', '\'', '"'), array('&amp;', '&lt;', '&gt;', '&apos;', '&quot;'), $string);
}

Add this to the first line of public function setValue in TemplateProcessor.php:
$replace = $this->xmlEscape($replace);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions