This article describes how to obtain the relative path of a file in PHP. using a user-defined function to obtain the relative path of a file is of reference value, for more information about how to obtain the relative file path of PHP, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:
<? Php $ a = '/a/B/c/d/e. php '; $ B ='/a/B/12/34/c. php ';//.. /.. /12/34/c. phpecho getRelativelyPath ($ a, $ B); // evaluate the relative path of $ B to $ a. function getRelativelyPath ($ a, $ B) {$ a = explode ('/', $ a); $ B = explode ('/', $ B); var_dump ($ a); // print_r ($ B ); $ c = array_values (array_diff ($ a, $ B); $ d = array_values (array_diff ($ B, $ a); // 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.