php-doc-en/reference/filesystem/functions/dirname.xml

100 lines
2.8 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.9 $ -->
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
<refentry id="function.dirname">
<refnamediv>
<refname>dirname</refname>
<refpurpose>Returns directory name component of path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>dirname</methodname>
<methodparam><type>string</type><parameter>path</parameter></methodparam>
</methodsynopsis>
<para>
Given a string containing a path to a file, this function will
return the name of the directory.
</para>
<para>
On Windows, both slash (<literal>/</literal>) and backslash
(<literal>\</literal>) are used as directory separator character. In
other environments, it is the forward slash
(<literal>/</literal>).
</para>
<para>
<example>
<title><function>dirname</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$path = "/etc/passwd";
$file = dirname($path); // $file is set to "/etc"
?>
]]>
</programlisting>
</example>
</para>
<note>
<para>
In PHP 4.0.3, <function>dirname</function> was fixed to be
POSIX-compliant. Essentially, this means that if there are no
slashes in <parameter>path</parameter> , a dot
('<literal>.</literal>') is returned, indicating the current
directory. Otherwise, the returned string is
<parameter>path</parameter> with any trailing
<literal>/component</literal> removed. Note that this means that
you will often get a slash or a dot back from
<function>dirname</function> in situations where the older
functionality would have given you the empty string.
</para>
</note>
<para>
<function>dirname</function> has changed its behaviour in PHP 4.3.0.
Check the following examples:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
//before PHP 4.3.0
dirname('c:/'); // returned '.'
//after PHP 4.3.0
dirname('c:/'); // returns 'c:'
?>
]]>
</programlisting>
</informalexample>
</para>
<para>
<function>dirname</function> has been binary safe since PHP 5.0.0
</para>
<para>
See also <function>basename</function>, <function>pathinfo</function>,
and <function>realpath</function>.
</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:"../../../../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
-->