1
0
mirror of https://github.com/php/doc-ja.git synced 2026-03-24 07:02:08 +01:00
Files
archived-doc-ja/reference/strings/functions/addcslashes.xml
Yoshinari Takaoka 4773312462 [ext/strings] followed all updates made on or after November 1, 2024.
- WASM の example 修正
- number_format まわりの誤訳
- その他細かい修正全てに追随

https://github.com/php/doc-en/commits/master/reference/strings
2025-08-23 15:55:59 +09:00

156 lines
5.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 45042fef652f1b4e904e809fcbfcf31f6c60670b Maintainer: hirokawa Status: ready -->
<!-- CREDITS: shimooka,mumumu -->
<refentry xml:id="function.addcslashes" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>addcslashes</refname>
<refpurpose>C 言語と同様にスラッシュで文字列をクォートする</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>addcslashes</methodname>
<methodparam><type>string</type><parameter>string</parameter></methodparam>
<methodparam><type>string</type><parameter>characters</parameter></methodparam>
</methodsynopsis>
<para>
<parameter>characters</parameter>
パラメータに羅列された文字の前にバックスラッシュを付けた文字列を返します。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>string</parameter></term>
<listitem>
<para>
エスケープしたい文字列。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>characters</parameter></term>
<listitem>
<para>
エスケープの対象となる文字を並べたもの。
<parameter>characters</parameter>
<literal>\n</literal>, <literal>\r</literal> 等の文字を含んでいる場合、
C言語と同様の手法によりエスケープされます。
アスキーコードが32未満または126より大きい文字は、8進表現に変換されます。
</para>
<para>
<parameter>characters</parameter> 引数の文字の列びを定義する際には、
範囲の最初と最後で指定する文字集合に含まれる文字の種類を把握するようにしてください。
<example>
<title>範囲指定で <function>addcslashes</function> を使う</title>
<programlisting role="php">
<![CDATA[
<?php
echo addcslashes('foo[ ]', 'A..z');
// 出力: \f\o\o\[ \]
// 全ての大文字と小文字はエスケープされます。
// ... しかし、[\]^_` もエスケープされてしまいます。
?>
]]>
</programlisting>
</example>
また、ある範囲を指定する最初の文字がその範囲の2番目の文字よりも大きな
ASCII 値を有している場合、範囲は定義されません。
最初と最後の文字とピリオド文字のみがエスケープされます。
ある文字の ASCII 値を見つけるには、
<function>ord</function> 関数を使用してください。
<example>
<title>誤った文字の順番を <function>addcslashes</function> に指定する</title>
<programlisting role="php">
<![CDATA[
<?php
echo addcslashes("zoo['.']", 'z..A');
// 出力: \zoo['\.']
?>
]]>
</programlisting>
</example>
</para>
<para>
0, a, b, f, n, r, t そして v といった文字をエスケープするときには注意しましょう。
変換結果はそれぞれ \0, \a, \b, \f, \n, \r, \t そして \v となりますが、
これらはすべて、C 言語では定義済みのエスケープシーケンスです。
その多くは C 言語に由来する他の言語でもエスケープシーケンスとして定義されており、
PHP も例外ではありません。つまり、<parameter>characters</parameter> にこれらの文字を定義した状態で
<function>addcslashes</function> を使って他の言語のコードを生成したときに、
期待通りの結果が得られない可能性があるということです。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
エスケープされた文字列を返します。
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
"\0..\37" のように <parameter>characters</parameter>
に範囲を指定可能です。この場合、アスキーコードが 0 から 31
の範囲の文字は全てエスケープされます。
<example>
<title><function>addcslashes</function> の例</title>
<programlisting role="php">
<![CDATA[
<?php
$not_escaped = "PHP isThirty\nYears Old!\tYay to the Elephant!\n";
$escaped = addcslashes($not_escaped, "\0..\37!@\177..\377");
echo $escaped;
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>stripcslashes</function></member>
<member><function>stripslashes</function></member>
<member><function>addslashes</function></member>
<member><function>htmlspecialchars</function></member>
<member><function>quotemeta</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->