mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 07:02:08 +01:00
154 lines
4.9 KiB
XML
154 lines
4.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 4225e50bc391ddba99e367c231463da0dc04357d Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: takagi,mumumu -->
|
|
<refentry xml:id="function.sscanf" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>sscanf</refname>
|
|
<refpurpose>フォーマット文字列に基づき入力を処理する</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>array</type><type>int</type><type>null</type></type><methodname>sscanf</methodname>
|
|
<methodparam><type>string</type><parameter>string</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>format</parameter></methodparam>
|
|
<methodparam rep="repeat"><type>mixed</type><parameter role="reference">vars</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
関数 <function>sscanf</function> は、<function>printf</function>
|
|
の入力版です。<function>sscanf</function> は、文字列
|
|
<parameter>string</parameter> を読み込み、これを指定したフォーマット
|
|
<parameter>format</parameter> に基づき解釈します。
|
|
</para>
|
|
<para>
|
|
フォーマット文字列の中のあらゆる空白文字は、入力文字列の中の
|
|
空白文字列にマッチします。つまり、フォーマット文字列の中にタブ文字
|
|
(<literal>\t</literal>) が含まれていても、
|
|
それは入力中の半角スペースにマッチしてしまうということです。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>string</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
入力文字列。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
&strings.scanf.parameter.format;
|
|
<varlistentry>
|
|
<term><parameter>vars</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
オプションで指定する参照渡しの変数に、
|
|
パースされた値が格納されます。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
この関数のパラメータが二つだけの場合、処理された値は配列として返されます。
|
|
それ以外の場合は、もしオプションのパラメータが渡されればこの関数は
|
|
割り当てられた値の数を返します。オプションのパラメータは
|
|
参照渡しにする必要があります。
|
|
</para>
|
|
<para>
|
|
<parameter>format</parameter> で期待する部分文字列のほうが
|
|
実際に <parameter>string</parameter> に存在するものより多い場合は
|
|
&null; を返します。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>sscanf</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// シリアル番号を得る
|
|
list($serial) = sscanf("SN/2350001", "SN/%d");
|
|
// 続いて製造日を得る
|
|
$mandate = "January 01 2000";
|
|
list($month, $day, $year) = sscanf($mandate, "%s %d %d");
|
|
echo "Item $serial was manufactured on: $year-" . substr($month, 0, 3) . "-$day\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
オプションのパラメータが指定された場合、この関数は、代入された値の数を返します。
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>sscanf</function> - オプションパラメータの使用法</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// author 情報を取得し、DocBook エントリを生成
|
|
$auth = "24\tLewis Carroll";
|
|
$n = sscanf($auth, "%d\t%s %s", $id, $first, $last);
|
|
echo "<author id='$id'>
|
|
<firstname>$first</firstname>
|
|
<surname>$last</surname>
|
|
</author>\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>printf</function></member>
|
|
<member><function>sprintf</function></member>
|
|
<member><function>fprintf</function></member>
|
|
<member><function>vprintf</function></member>
|
|
<member><function>vsprintf</function></member>
|
|
<member><function>vfprintf</function></member>
|
|
<member><function>fscanf</function></member>
|
|
<member><function>number_format</function></member>
|
|
<member><function>date</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
|
|
-->
|