Skip to content

Commit 7e2fd55

Browse files
committed
Add a separate example section for escaping of characters
See also merged PR php/php-src#7420 (php/php-src@d3a6054) php/doc-en@33225f7
1 parent c77a858 commit 7e2fd55

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

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

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: a453c4ff1cac60f674ca6739695c2990e3150e9f Maintainer: hirokawa Status: ready -->
3+
<!-- EN-Revision: 33225f7c5759ebd29496e98a55a3e4ba58cb1ac4 Maintainer: hirokawa Status: ready -->
44
<!-- CREDITS: shimooka,mumumu -->
55
<refentry xml:id="function.parse-ini-file" xmlns="http://docbook.org/ns/docbook">
66
<refnamediv>
@@ -253,17 +253,71 @@ negative_two = ~1
253253
; () はグループ化に使います
254254
seven = (8|7)&(6|5)
255255
256-
; \ は値のエスケープに使います
257-
newline_is = "\\n" ; results in the string "\n", not a newline character.
258-
with quotes = "She said \"Exactly my point\"." ; Results in a string with quote marks in it.
259-
260256
path = ${PATH}
261257
also_five = ${five}
262258
263259
]]>
264260
</programlisting>
265261
</example>
266262
</para>
263+
<para>
264+
<example>
265+
<title>文字をエスケープする</title>
266+
<para>
267+
文字によっては、ダブルクォートで囲まれた文字列の中で特別な意味を持つ場合があり、
268+
その場合、バックスラッシュでエスケープしなければなりません。
269+
特別な意味を持つのは、文字列の境目の印となるダブルクォート <code>"</code>、
270+
および、バックスラッシュ <code>\</code> (この文字の後に特別な文字がひとつ続きます) そのものです。
271+
</para>
272+
<programlisting>
273+
<![CDATA[
274+
quoted = "She said \"Exactly my point\"." ; Results in a string with quote marks in it.
275+
hint = "Use \\\" to escape double quote" ; Results in: Use \" to escape double quote
276+
]]>
277+
</programlisting>
278+
<para>
279+
Windows ライクなパスについては例外があります。
280+
クォートされた文字列のすぐ後に改行文字が続いた場合、
281+
末尾のバックスラッシュはエスケープする必要がないというものです。
282+
</para>
283+
<programlisting>
284+
<![CDATA[
285+
save_path = "C:\Temp\"
286+
]]>
287+
</programlisting>
288+
<para>
289+
複数行にまたがる値で、改行文字が直後にあるダブルクォート文字をエスケープする必要がある場合、
290+
次のようにして値を連結することでそれを実現できます。
291+
(ダブルクォートで囲まれた文字列がひとつあり、その直後にもうひとつの文字列が続きます)
292+
</para>
293+
<programlisting>
294+
<![CDATA[
295+
long_text = "Lorem \"ipsum\"""
296+
dolor" ; Results in: Lorem "ipsum"\n dolor
297+
]]>
298+
</programlisting>
299+
<para>
300+
特別な意味を持つ別の文字として、<code>$</code> (ドル記号) があります。
301+
これは、開き括弧が続く場合、エスケープしなければいけません:
302+
</para>
303+
<programlisting>
304+
<![CDATA[
305+
code = "\${test}"
306+
]]>
307+
</programlisting>
308+
<para>
309+
文字のエスケープは、
310+
<constant>INI_SCANNER_RAW</constant> モードではサポートされていません。
311+
(このモードでは、全ての文字が "そのまま" 処理されます)
312+
</para>
313+
<para>
314+
ini ファイルのパーサーは、標準的なエスケープシーケンス
315+
(<code>\n</code>, <code>\t</code>, など) をサポートしていないことに注意して下さい。
316+
そのサポートが必要な場合、<function>parse_ini_file</function> の処理結果を
317+
<function>stripcslashes</function> で処理するようにして下さい。
318+
</para>
319+
</example>
320+
</para>
267321
</refsect1>
268322

269323
<refsect1 role="notes">

0 commit comments

Comments
 (0)