PHP method for obtaining the relative file path. _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.