PHP to obtain the relative path of the file. PHP file relative path retrieval method this article mainly introduces the PHP method for obtaining the relative path of a file. you can use a user-defined function to obtain the relative path of a file, you can refer to PHP to obtain the relative file path.
This article mainly introduces how to obtain the relative path of a file in PHP. using a user-defined function to obtain the relative path of a file has some reference value. if you need it, refer
This example describes how to obtain the relative path of a file in PHP. Share it with you for your reference. The specific implementation method is as follows:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 |
$ A = '/a/B/c/d/e. php ';
$ B = '/a/B/12/34/c. php ';
/// ../12/34/c. php
Echo getRelativelyPath ($ a, $ B );
// Calculate the relative path of $ B relative to $
Function getRelativelyPath ($ a, $ B ){
$ A = explode ('/', $ );
$ B = explode ('/', $ B );
Var_dump ($ );
// Print_r ($ B );
$ C = array_values (array_diff ($ a, $ B ));
$ D = array_values (array_diff ($ B, $ ));
// Var_dump ($ c );
// Var_dump ($ d );
Array_pop ($ c );
Foreach ($ c as & $ v ){
$ V = '..';
}
Var_dump ($ c );
Var_dump ($ d );
$ Arr = array_merge ($ c, $ d );
Var_dump ($ arr );
$ Str = implode ("/", $ arr );
Echo $ str;
}
|
I hope this article will help you with php programming.
This article describes how to obtain the relative path of a file in PHP. you can use a user-defined function to obtain the relative path of a file...