Skip to content

XML escape for templateprocessor setValue #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
evotodi opened this issue Feb 26, 2016 · 3 comments
Closed

XML escape for templateprocessor setValue #746

evotodi opened this issue Feb 26, 2016 · 3 comments

Comments

@evotodi
Copy link

evotodi commented Feb 26, 2016

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);

@pv451
Copy link

pv451 commented Mar 6, 2016

Actually you may just call setValue as it done in samples setValue('some',htmlspecialchars($some));

@ghost ghost added this to the v0.13.0 milestone Jul 9, 2016
@ghost ghost self-assigned this Jul 9, 2016
@ghost
Copy link

ghost commented Jul 9, 2016

#671 (comment).

@ghost ghost closed this as completed Jul 9, 2016
@SadPencil
Copy link

@pv451 I don't agree. Take an example, ¢£¥€§©®™×÷
these character shouldn't be converted to html entities.
Only "'&<> should be converted.
htmlentities() is not suitable. str_replace()is better.

@SadPencil SadPencil unassigned ghost Sep 10, 2017
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants