mirror of
https://github.com/php/doc-ja.git
synced 2026-03-27 00:22:08 +01:00
259 lines
7.4 KiB
XML
259 lines
7.4 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: d0cc084a925f112c156d0dbac12718b2bd8d4889 Maintainer: hirokawa Status: ready -->
|
|
<!-- Credits: mumumu -->
|
|
<refentry xml:id="function.pathinfo" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>pathinfo</refname>
|
|
<refpurpose>ファイルパスに関する情報を返す</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>array</type><type>string</type></type><methodname>pathinfo</methodname>
|
|
<methodparam><type>string</type><parameter>path</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>PATHINFO_ALL</constant></initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>pathinfo</function> は、<parameter>path</parameter>
|
|
に関する情報を返します。<parameter>flags</parameter>
|
|
によって連想配列あるいは文字列のどちらかとなります。
|
|
</para>
|
|
<note>
|
|
<para>
|
|
カレントのパスに関する情報を取得するには、
|
|
<link linkend="language.variables.predefined">定義済みの変数</link>
|
|
のセクションをご覧ください。
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
<function>pathinfo</function> は入力された文字列をそのまま扱います。
|
|
よって、実際のファイルシステムや
|
|
"<literal>..</literal>" のようなパスコンポーネントも認識しません。
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
Windows システムでのみ、<literal>\</literal> 文字はディレクトリのセパレータとして解釈されます。
|
|
それ以外のシステムでは、他の文字と同じように扱われます。
|
|
</para>
|
|
</note>
|
|
<caution>
|
|
<para>
|
|
<function>pathinfo</function> はロケールを考慮して処理を行います。
|
|
マルチバイト文字を含むパスを正しく処理するには、正しいロケールを
|
|
<function>setlocale</function> 関数で設定しておかなければなりません。
|
|
</para>
|
|
</caution>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>path</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
調べたいパス。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>flags</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
指定する場合は、どの要素を返すのかを
|
|
<constant>PATHINFO_DIRNAME</constant>、
|
|
<constant>PATHINFO_BASENAME</constant>、
|
|
<constant>PATHINFO_EXTENSION</constant> あるいは
|
|
<constant>PATHINFO_FILENAME</constant>
|
|
のいずれかで指定します。
|
|
</para>
|
|
<para>
|
|
<parameter>flags</parameter> を省略した場合はすべての要素を返します。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
<parameter>flags</parameter> パラメータを渡さなかった場合は、次の要素を含む連想配列を返します。
|
|
<literal>dirname</literal>、<literal>basename</literal>、
|
|
<literal>extension</literal> (存在すれば)、そして <literal>filename</literal>。
|
|
</para>
|
|
<note>
|
|
<para>
|
|
<parameter>path</parameter> に複数の拡張子が含まれる場合は、
|
|
<constant>PATHINFO_EXTENSION</constant> は最後の拡張子だけを返します。また、
|
|
<constant>PATHINFO_FILENAME</constant> は最後の拡張子だけを取り除きます
|
|
(最初のサンプルを参照ください)。
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
<parameter>path</parameter> に拡張子がない場合は、
|
|
<literal>extension</literal> 要素は返されません
|
|
(以下の二番目の例を参照ください)。
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
<parameter>path</parameter> の <literal>basename</literal>
|
|
がドットで始まる場合は、それに続く文字は
|
|
<literal>extension</literal> とみなされます。そして <literal>filename</literal>
|
|
は空文字列となります (以下の三番目の例を参照ください)。
|
|
</para>
|
|
</note>
|
|
<para>
|
|
<parameter>flags</parameter> を指定すると、
|
|
要求した要素を文字列で返します。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>pathinfo</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
|
|
|
|
echo $path_parts['dirname'], "\n";
|
|
echo $path_parts['basename'], "\n";
|
|
echo $path_parts['extension'], "\n";
|
|
echo $path_parts['filename'], "\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
/www/htdocs/inc
|
|
lib.inc.php
|
|
php
|
|
lib.inc
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>pathinfo</function> での、拡張子を空にしたときと拡張子がないときの違いの例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$path_parts = pathinfo('/path/emptyextension.');
|
|
var_dump($path_parts['extension']);
|
|
|
|
$path_parts = pathinfo('/path/noextension');
|
|
var_dump($path_parts['extension']);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
string(0) ""
|
|
|
|
Notice: Undefined index: extension in test.php on line 6
|
|
NULL
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>pathinfo</function> での、ドットファイルの例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
print_r(pathinfo('/some/path/.test'));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[dirname] => /some/path
|
|
[basename] => .test
|
|
[extension] => test
|
|
[filename] =>
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>配列の分解機能を、<function>pathinfo</function> と一緒に使う例</title>
|
|
<para>
|
|
<parameter>flags</parameter> パラメータは、ビットマスクではありません。
|
|
単一の値だけを指定できます。
|
|
パース済みの値の限られた一部を選択したい場合、
|
|
配列を分解する機能を以下のようにして使います:
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
['basename' => $basename, 'dirname' => $dirname] = pathinfo('/www/htdocs/inc/lib.inc.php');
|
|
|
|
var_dump($basename, $dirname);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
string(11) "lib.inc.php"
|
|
string(15) "/www/htdocs/inc"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>dirname</function></member>
|
|
<member><function>basename</function></member>
|
|
<member><function>parse_url</function></member>
|
|
<member><function>realpath</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
|
|
-->
|