# \[PHP\] Resolve a relative url from 1 file to another given the 2 files paths

**URL:** <https://forum.kirupa.com/t/php-resolve-a-relative-url-from-1-file-to-another-given-the-2-files-paths/207070>\
**Category:** programming\
**Created:** [November 14, 2006, 3:46pm UTC](https://forum.kirupa.com/t/php-resolve-a-relative-url-from-1-file-to-another-given-the-2-files-paths/207070 "2006-11-14T15:46:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [November 14, 2006, 3:46pm UTC](https://forum.kirupa.com/t/php-resolve-a-relative-url-from-1-file-to-another-given-the-2-files-paths/207070/1 "2006-11-14T15:46:21Z")

</div>

Using PHP, is there any way to easily resolve a relative url from one path to another?

EX:  
file1: sub/file1.html  
file2: file2.html  
result (from file1): …/file2.html

I can parse it myself by going through the path and comparing the parts, but I was wondering if there was some other way or some method that did this automatically. Any ideas?
