Phpword: Content fails at ampersand(&) symbol

Created on 26 Aug 2016  Â·  3Comments  Â·  Source: PHPOffice/PHPWord

PHPWord fails to render content following & symbol. Any idea how to resolve this?

401

Most helpful comment

Check out http://phpword.readthedocs.io/en/latest/general.html#output-escaping — automatic output escaping was added in 0.13.0, but you need to opt in.

All 3 comments

Resolved by using htmlspecialchars()

Check out http://phpword.readthedocs.io/en/latest/general.html#output-escaping — automatic output escaping was added in 0.13.0, but you need to opt in.

Output escaping
Writing documents of some formats, especially XML-based, requires correct output escaping. Without it your document may become broken when you put special characters like ampersand, quotes, and others in it.

Escaping can be performed in two ways: outside of the library by a software developer and inside of the library by built-in mechanism. By default, the built-in mechanism is disabled for backward compatibility with versions prior to v0.13.0. To turn it on set outputEscapingEnabled option to true in your PHPWord configuration file or use the following instruction at runtime:

\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);

Was this page helpful?
0 / 5 - 0 ratings