Hàm pathinfo[] sẽ lấy thông tin về đường dẫn truyền vào.
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.freetuts.net, không được copy dưới mọi hình thức.
Cú pháp
Cú pháp: pathinfo[ $path, $option];: pathinfo[ $path, $option];
Trong đó::
- $path là đường dẫn cần lấy thông tin.
- $option là tham số không bắt buộc, có thể mang một trong các giá trị sau: PATHINFO_DIRNAME, PATHINFO_BASENAME, PATHINFO_EXTENSION , PATHINFO_FILENAME.
Kết quả trả về
- Nếu $option không được truyền vào, hàm sẽ trả về một mảng bao gồm các phần tử: dirname, basename, extension[ nếu đường dẫn truyền vào không có phần mở rộng thì mảng trả về sẽ không có phần tử extension], and filename.
- Nếu $option được truyền vào hàm sẽ trả về chuỗi là giá trị mà $option yêu cầu.
Ví dụ
Ví dụ về cách sử dụng hàm pathinfo[]:
Bài viết này được đăng tại [free tuts .net]
Code
$path = 'C:\xampp\php\php.ini'; $arr = pathinfo[$path]; echo ""; print_r[$arr]; echo "";Kết quả
Array [ [dirname] => C:\xampp\php [basename] => php.ini [extension] => ini [filename] => php ]Sử dụng tham số $option:
Code
$path = 'C:\xampp\php\php.ini'; $arr = pathinfo[$path]; echo ""; print_r[$arr]; echo "";Kết quả
[Php 4> = 4.0.3, Php 5, Php 7, Php 8]
Nội dung chính ShowShow
- Sự mô tả
- pathInfo [] là nhận thức được ngôn ngữ, vì vậy để nó phân tích một đường dẫn chứa các ký tự multibyte một cách chính xác, locale phù hợp phải được đặt bằng hàm setLocale [].
- Nếu flags không được chỉ định, hãy trả về tất cả các yếu tố có sẵn.
- Thận trọng
- ________số 8
PathInfo - Trả về thông tin về đường dẫn tệp — Returns information about a file path — Returns information about a file path
Sự mô tả
pathInfo [] là nhận thức được ngôn ngữ, vì vậy để nó phân tích một đường dẫn chứa các ký tự multibyte một cách chính xác, locale phù hợp phải được đặt bằng hàm setLocale [].[string string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
7, int string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
8 =
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
9]: array|string
Nếu flags không được chỉ định, hãy trả về tất cả các yếu tố có sẵn.:
Thận trọng
Nếu flags không được chỉ định, hãy trả về tất cả các yếu tố có sẵn.:
Thận trọng operates naively on the input string, and is not aware of the actual filesystem, or path components such as "
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL3".
________số 8
PathInfo - Trả về thông tin về đường dẫn tệp — Returns information about a file path is locale aware, so for it to parse a path containing multibyte characters correctly, the matching locale must be set using the setlocale[] function.
pathInfo [] là nhận thức được ngôn ngữ, vì vậy để nó phân tích một đường dẫn chứa các ký tự multibyte một cách chính xác, locale phù hợp phải được đặt bằng hàm setLocale [].
Nếu flags không được chỉ định, hãy trả về tất cả các yếu tố có sẵn.Thận trọng
________số 8PathInfo - Trả về thông tin về đường dẫn tệp — Returns information about a file pathstring[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
6,
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL7, int
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL8 =
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL9]: mảng | chuỗi[string
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL7, int
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL8 =
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL9]: array|string0,
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL1 or
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL2.
Ghi chú::
Để biết thông tin về việc truy xuất thông tin đường dẫn hiện tại, hãy đọc phần về các biến được đặt trước được xác định trước.Nếu flags không được chỉ định, hãy trả về tất cả các yếu tố có sẵn.
Thận trọngarray containing the following elements is returned:
________số 8Nếu flags không được chỉ định, hãy trả về tất cả các yếu tố có sẵn.:
Thận trọng
________số 81 returns only the last one andstring[0] "" Notice: Undefined index: extension in test.php on line 6 NULL2 only strips the last one. [see first example below].
Nếu flags không được chỉ định, hãy trả về tất cả các yếu tố có sẵn.:
Thận trọng
Nếu flags không được chỉ định, hãy trả về tất cả các yếu tố có sẵn.:
Thận trọng
________số 8string containing the requested element.
Thận trọng
________số 8pathinfo[] Example
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL29
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL70
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL71
Nếu flags không được chỉ định, hãy trả về tất cả các yếu tố có sẵn.
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL3
Thận trọngpathinfo[] example showing difference between null and no extension
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL72
________số 8
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL
PathInfo - Trả về thông tin về đường dẫn tệp — Returns information about a file pathpathinfo[] example for a dot-file
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL73
________số 8
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL2
________số 8
- PathInfo - Trả về thông tin về đường dẫn tệp — Returns information about a file path
- pathinfo [chuỗi
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL
7, intstring[0] "" Notice: Undefined index: extension in test.php on line 6 NULL
8 =string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL
9]: mảng | chuỗi[stringstring[0] "" Notice: Undefined index: extension in test.php on line 6 NULL
7, intstring[0] "" Notice: Undefined index: extension in test.php on line 6 NULL
8 =string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL
9]: array|string - Ghi chú::
- Để biết thông tin về việc truy xuất thông tin đường dẫn hiện tại, hãy đọc phần về các biến được đặt trước được xác định trước.
Để biết thông tin về việc truy xuất thông tin đường dẫn hiện tại, hãy đọc phần về các biến được đặt trước được xác định trước. operates naively on the input string, and is not aware of the actual filesystem, or path components such as "string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
3".
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL3".1 chỉ trả về cái cuối cùng và
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL2 chỉ dải cái cuối cùng. [Xem ví dụ đầu tiên dưới đây]. ¶
Thận trọng is locale aware, so for it to parse a path containing multibyte characters correctly, the matching locale must be set using the setlocale[] function.
Thông số7 [xem ví dụ thứ hai bên dưới].string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL74
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
5
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL5 bắt đầu bằng một dấu chấm, các ký tự sau được hiểu là
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL7 và
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL8 trống [xem ví dụ thứ ba bên dưới]. ¶
________số 8string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
6,
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL75
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL76
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL77
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL78
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
0, string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
1 or string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
2. ¶
Nếu có, chỉ định một yếu tố cụ thể sẽ được trả về; một trong số string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
6,
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL80
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL81
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL82
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL83
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL84
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL85
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
0, string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
1 hoặc string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
2. ¶
Trả về giá trịarray containing the following elements is returned:
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL86
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL87
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
5, string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
6, string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
7 [if any], and string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
8. ¶
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
1 returns only the last one and string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
2 only strips the last one. [see first example below].
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL89
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL90
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
Xem thêm ¶ ¶
Dirname [] - Trả về đường dẫn của thư mục cha mẹ
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL92
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL93
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
basename [] - Trả về thành phần tên dấu vết của đường dẫn ¶ ¶
parse_url [] - phân tích URL và trả về các thành phần của nó
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL95
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL96
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL97
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL98
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
RealPath [] - Trả về tên đường dẫn tuyệt đối chính thức ¶ ¶
Lori ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL30
4 năm trước ¶ ¶
498936940 tại qq dot com ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL31
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL32
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL33
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL34
6 năm trước ¶ ¶
Thông tin tại KGSW DOT de ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL35
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL36
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL37
1 năm trước ¶ ¶
Thông tin tại KGSW DOT de ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL38
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL36
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL37
1 năm trước ¶ ¶
Ví dụ #3 PathInfo [] Ví dụ cho tệp chấm
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL51
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL52
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
Xem thêm ¶ ¶
Ví dụ #3 PathInfo [] Ví dụ cho tệp chấm
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL54
Xem thêm ¶ ¶
Dirname [] - Trả về đường dẫn của thư mục cha mẹ
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL55
basename [] - Trả về thành phần tên dấu vết của đường dẫn ¶ ¶
Ví dụ #3 PathInfo [] Ví dụ cho tệp chấm
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL56
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL57
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL58
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL59
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
Xem thêm ¶ ¶
Ví dụ #3 PathInfo [] Ví dụ cho tệp chấm
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL51
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL52
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL53
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL54
Xem thêm ¶ ¶
498936940 tại qq dot com ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL55
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL56
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
6 năm trước ¶ ¶
Thông tin tại KGSW DOT de ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL58
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL59
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
1 năm trước ¶ ¶
498936940 tại qq dot com ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL61
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL62
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
6 năm trước ¶ ¶
Thông tin tại KGSW DOT de ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL64
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL65
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL66
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL67
1 năm trước ¶ ¶
Lori ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL68
4 năm trước ¶ ¶
498936940 tại qq dot com ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL69
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL00
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL01
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL02
6 năm trước ¶ ¶
parse_url [] - phân tích URL và trả về các thành phần của nó
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL03
RealPath [] - Trả về tên đường dẫn tuyệt đối chính thức ¶ ¶
498936940 tại qq dot com ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL04
6 năm trước ¶ ¶
Thông tin tại KGSW DOT de ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL05
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL06
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL07
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL08
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
1 năm trước ¶ ¶
Ví dụ #3 PathInfo [] Ví dụ cho tệp chấm
Pietro Baricco ¶ string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
10string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
1110 năm trước ¶
parse_url [] - phân tích URL và trả về các thành phần của nó
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL13
RealPath [] - Trả về tên đường dẫn tuyệt đối chính thức ¶ ¶
Ví dụ #3 PathInfo [] Ví dụ cho tệp chấm
Pietro Baricco ¶Xem thêm ¶ ¶
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
10string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
1110 năm trước
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
10string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
1110 năm trước ¶
498936940 tại qq dot com ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL27
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL28
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL29
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL30
6 năm trước ¶ ¶
Ví dụ #3 PathInfo [] Ví dụ cho tệp chấm
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL31
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL36
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL33
Pietro Baricco ¶ ¶
498936940 tại qq dot com ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL34
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL35
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL36
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
6 năm trước ¶ ¶
Thông tin tại KGSW DOT de ¶
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL38
1 năm trước ¶ ¶
parse_url [] - phân tích URL và trả về các thành phần của nó
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL39
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL40
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
RealPath [] - Trả về tên đường dẫn tuyệt đối chính thức ¶ ¶
Ví dụ #3 PathInfo [] Ví dụ cho tệp chấm
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL42
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL43
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
Pietro Baricco ¶ ¶
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
10string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
1110 năm trước
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL45
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL46
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL36
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL48
Tom tại Foo-Bar Dot Co Dot Uk ¶ ¶ ¶
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
14string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
15 string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
01string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
17
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL49
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL50
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL51
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL79
Ví dụ #1 PathInfo [] Ví dụ ¶
string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
18string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
19string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
20string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
21string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
22string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
23string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
24string[0] ""
Notice: Undefined index: extension in test.php on line 6
NULL
2510 năm trước
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL53
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL54
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL55
string[0] "" Notice: Undefined index: extension in test.php on line 6 NULL56