0

Using PHPWord, I've managed with this line:

$section->addText('<');

to provoke an Error in Microsoft Word opening the .docx file:

+---------------------------------------------------------------+
| Microsoft Office Word                                     ? X |
+---------------------------------------------------------------+
| The file BrynergyTest.docx cannot be opened because there are |
| problems with the contents.                                   |
|                                        [ OK ] [ Details >>> ] |
+---------------------------------------------------------------+

Microsoft Office Word showing a message box dialog with the message "The file BrynergyTest.docx cannot be opened because there are problems with the contents." with an "OK" and a button to show more details.

Other symbols, such as:

$section->addText('t');

work fine.

I expected the result to have the Word XML file with the contents of the less-than-sign "<" (U+003C LESS-THAN SIGN).

1 Answer 1

2

I found this answer:

\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
Sign up to request clarification or add additional context in comments.

4 Comments

As per documentation: "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." phpword.readthedocs.io/en/latest/general.html#output-escaping
"I found this answer" Where?
@Cymro: Please edit that into your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.