Skip to content

Commit 33225f7

Browse files
authored
Add a separate example section for escaping of characters
See also merged PR php/php-src#7420 (php/php-src@d3a6054) Closes GH-898.
1 parent 08a9415 commit 33225f7

File tree

1 file changed

+54
-5
lines changed

1 file changed

+54
-5
lines changed

reference/filesystem/functions/parse-ini-file.xml

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ echo '(loaded) magic_quotes_gpc = ' . yesno(get_cfg_var('magic_quotes_gpc')) . P
227227
</para>
228228
<para>
229229
<example>
230-
<title>value interpolation</title>
230+
<title>Value Interpolation</title>
231231
<para>
232232
In addition to evaluating constants, certain characters have special meaning in an ini value.
233233
Additionally, environment variables and previously defined values may be read using
@@ -250,17 +250,66 @@ negative_two = ~1
250250
; () is used for grouping
251251
seven = (8|7)&(6|5)
252252
253-
; \ is used to escape a value.
254-
newline_is = "\\n" ; results in the string "\n", not a newline character.
255-
with quotes = "She said \"Exactly my point\"." ; Results in a string with quote marks in it.
256-
257253
path = ${PATH}
258254
also_five = ${five}
259255
260256
]]>
261257
</programlisting>
262258
</example>
263259
</para>
260+
<para>
261+
<example>
262+
<title>Escaping Characters</title>
263+
<para>
264+
Some characters have special meaning in double-quoted strings and must be escaped by the backslash prefix.
265+
First of all, these are the double quote <code>"</code> as the boundary marker, and the backslash <code>\</code> itself
266+
(if followed by one of the special characters):
267+
</para>
268+
<programlisting>
269+
<![CDATA[
270+
quoted = "She said \"Exactly my point\"." ; Results in a string with quote marks in it.
271+
hint = "Use \\\" to escape double quote" ; Results in: Use \" to escape double quote
272+
]]>
273+
</programlisting>
274+
<para>
275+
There is an exception made for Windows-like paths: it's possible to not escape trailing backslash
276+
if the quoted string is directly followed by a linebreak:
277+
</para>
278+
<programlisting>
279+
<![CDATA[
280+
save_path = "C:\Temp\"
281+
]]>
282+
</programlisting>
283+
<para>
284+
If one does need to escape double quote followed by linebreak in a multiline value,
285+
it's possible to use value concatenation in the following way
286+
(there is one double-quoted string directly followed by another one):
287+
</para>
288+
<programlisting>
289+
<![CDATA[
290+
long_text = "Lorem \"ipsum\"""
291+
dolor" ; Results in: Lorem "ipsum"\n dolor
292+
]]>
293+
</programlisting>
294+
<para>
295+
Another character with special meaning is <code>$</code> (the dollar sign).
296+
It must be escaped if followed by the open curly brace:
297+
</para>
298+
<programlisting>
299+
<![CDATA[
300+
code = "\${test}"
301+
]]>
302+
</programlisting>
303+
<para>
304+
Escaping characters is not supported in the <constant>INI_SCANNER_RAW</constant> mode
305+
(in this mode all characters are processed "as is").
306+
</para>
307+
<para>
308+
Note that the ini parser doesn't support standard escape sequences (<code>\n</code>, <code>\t</code>, etc.).
309+
If necessary, post-process the result of <function>parse_ini_file</function> with <function>stripcslashes</function> function.
310+
</para>
311+
</example>
312+
</para>
264313
</refsect1>
265314

266315
<refsect1 role="notes">

0 commit comments

Comments
 (0)