pathinfo

(PHP 4 >= 4.0.3, PHP 5, PHP 7)

pathinfo�����ļ�·������Ϣ

˵��

pathinfo ( string $path [, int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ] ) : mixed

pathinfo() ����һ��������������� path ����Ϣ�����ع������黹���ַ���ȡ���� options��

����

path

Ҫ������·����

options

���ָ���ˣ����᷵��ָ��Ԫ�أ����ǰ�����PATHINFO_DIRNAME��PATHINFO_BASENAME �� PATHINFO_EXTENSION �� PATHINFO_FILENAME��

���û��ָ�� options Ĭ���Ƿ���ȫ���ĵ�Ԫ��

����ֵ

���û�д��� options �����᷵�ذ������µ�Ԫ������ array��dirname��basename �� extension������У����� ��filename��

Note:

If the path does not have an extension, no extension element will be returned�����µڶ�����������

If options is present, returns a string containing the requested element.

������־

�汾 ˵��
5.2.0 ����˳��� PATHINFO_FILENAME��

����

Example #1 pathinfo() ����

<?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"// since PHP 5.2.0
?>

�������̻������

/www/htdocs/inc
lib.inc.php
php
lib.inc

Example #2 pathinfo() example showing difference between null and no extension

<?php
$path_parts 
pathinfo('/path/emptyextension.');
var_dump($path_parts['extension']);

$path_parts pathinfo('/path/noextension');
var_dump($path_parts['extension']);
?>

�������̵���������ڣ�

string(0) ""

Notice: Undefined index: extension in test.php on line 6
NULL

ע��

Note:

�й�ȡ�õ�ǰ·����Ϣ��˵�������Ķ�Ԥ�������һ�ڡ�

Note:

pathinfo() is locale aware, so for it to parse a path containing multibyte characters correctly, the matching locale must be set using the setlocale() function.

�μ�

  • dirname() - ����·���е�Ŀ¼����
  • basename() - ����·���е��ļ�������
  • parse_url() - ���� URL����������ɲ���
  • realpath() - ���ع淶���ľ���·����