Skip to content

Commit ec3c62b

Browse files
author
Roman Syroeshko
committedJun 4, 2016
PHPOffice#483. Output escaping for OOXML.
1 parent 4954f28 commit ec3c62b

File tree

81 files changed

+790
-697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+790
-697
lines changed
 

‎README.md

+10-18
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,9 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
9393
$section = $phpWord->addSection();
9494
// Adding Text element to the Section having font styled by default...
9595
$section->addText(
96-
htmlspecialchars(
97-
'"Learn from yesterday, live for today, hope for tomorrow. '
98-
. 'The important thing is not to stop questioning." '
99-
. '(Albert Einstein)'
100-
)
96+
'"Learn from yesterday, live for today, hope for tomorrow. '
97+
. 'The important thing is not to stop questioning." '
98+
. '(Albert Einstein)'
10199
);
102100

103101
/*
@@ -109,11 +107,9 @@ $section->addText(
109107

110108
// Adding Text element with font customized inline...
111109
$section->addText(
112-
htmlspecialchars(
113-
'"Great achievement is usually born of great sacrifice, '
114-
. 'and is never the result of selfishness." '
115-
. '(Napoleon Hill)'
116-
),
110+
'"Great achievement is usually born of great sacrifice, '
111+
. 'and is never the result of selfishness." '
112+
. '(Napoleon Hill)',
117113
array('name' => 'Tahoma', 'size' => 10)
118114
);
119115

@@ -124,11 +120,9 @@ $phpWord->addFontStyle(
124120
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
125121
);
126122
$section->addText(
127-
htmlspecialchars(
128-
'"The greatest accomplishment is not in never falling, '
129-
. 'but in rising again after you fall." '
130-
. '(Vince Lombardi)'
131-
),
123+
'"The greatest accomplishment is not in never falling, '
124+
. 'but in rising again after you fall." '
125+
. '(Vince Lombardi)',
132126
$fontStyleName
133127
);
134128

@@ -137,9 +131,7 @@ $fontStyle = new \PhpOffice\PhpWord\Style\Font();
137131
$fontStyle->setBold(true);
138132
$fontStyle->setName('Tahoma');
139133
$fontStyle->setSize(13);
140-
$myTextElement = $section->addText(
141-
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
142-
);
134+
$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)');
143135
$myTextElement->setFontStyle($fontStyle);
144136

145137
// Saving the document as OOXML file...

‎docs/general.rst

+25-25
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
2424
$section = $phpWord->addSection();
2525
// Adding Text element to the Section having font styled by default...
2626
$section->addText(
27-
htmlspecialchars(
28-
'"Learn from yesterday, live for today, hope for tomorrow. '
29-
. 'The important thing is not to stop questioning." '
30-
. '(Albert Einstein)',
31-
ENT_COMPAT,
32-
'UTF-8'
33-
)
27+
'"Learn from yesterday, live for today, hope for tomorrow. '
28+
. 'The important thing is not to stop questioning." '
29+
. '(Albert Einstein)'
3430
);
3531
3632
/*
@@ -42,13 +38,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
4238
4339
// Adding Text element with font customized inline...
4440
$section->addText(
45-
htmlspecialchars(
46-
'"Great achievement is usually born of great sacrifice, '
47-
. 'and is never the result of selfishness." '
48-
. '(Napoleon Hill)',
49-
ENT_COMPAT,
50-
'UTF-8'
51-
),
41+
'"Great achievement is usually born of great sacrifice, '
42+
. 'and is never the result of selfishness." '
43+
. '(Napoleon Hill)',
5244
array('name' => 'Tahoma', 'size' => 10)
5345
);
5446
@@ -59,13 +51,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
5951
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
6052
);
6153
$section->addText(
62-
htmlspecialchars(
63-
'"The greatest accomplishment is not in never falling, '
64-
. 'but in rising again after you fall." '
65-
. '(Vince Lombardi)',
66-
ENT_COMPAT,
67-
'UTF-8'
68-
),
54+
'"The greatest accomplishment is not in never falling, '
55+
. 'but in rising again after you fall." '
56+
. '(Vince Lombardi)',
6957
$fontStyleName
7058
);
7159
@@ -74,9 +62,7 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
7462
$fontStyle->setBold(true);
7563
$fontStyle->setName('Tahoma');
7664
$fontStyle->setSize(13);
77-
$myTextElement = $section->addText(
78-
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)', ENT_COMPAT, 'UTF-8')
79-
);
65+
$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)');
8066
$myTextElement->setFontStyle($fontStyle);
8167
8268
// Saving the document as OOXML file...
@@ -130,8 +116,22 @@ included with PHPWord.
130116
131117
\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
132118
119+
Output escaping
120+
~~~~~~~~~~~~~~~
121+
122+
Writing documents of some formats, especially XML-based, requires correct output escaping.
123+
Without it your document may become broken when you put special characters like ampersand, quotes, and others in it.
124+
125+
Escaping can be performed in two ways: outside of the library by a software developer and inside of the library by built-in mechanism.
126+
By default, the built-in mechanism is disabled for backward compatibility with versions prior to v0.13.0.
127+
To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord configuration file or use the following instruction at runtime:
128+
129+
.. code-block:: php
130+
131+
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
132+
133133
Default font
134-
------------
134+
~~~~~~~~~~~~
135135

136136
By default, every text appears in Arial 10 point. You can alter the
137137
default font by using the following two functions:

0 commit comments

Comments
 (0)
Please sign in to comment.