PHP method for obtaining the relative file path _ PHP Tutorial

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

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.