PHP to obtain the relative file path ,. PHP obtains the relative path of a file. This article describes how PHP obtains the relative path of a file. Share it with you for your reference. The specific implementation method is as follows: php $ aabcde PHP obtains the file relative path,
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:
<? 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.
Example: This article 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: php $ a = '/a/B/c/d/e...