note 60411 deleted from function.realpath by nlopess
| From: | nlopess@php.net | Date: | Wed, 08 Mar 2006 10:24:17 +0000 |
| Subject: | note 60411 deleted from function.realpath by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-105040@lists.php.net to get a copy of this message | ||
Note Submitter: john (at) juracid.co.uk
----
I found realpath stopped working when I moved to a shared hosting server.
I was using it to determine relative paths between files, basically changing paths like:
user/stuff/things/../items/file.htm
to
user/stuff/items/file.htm
Since I don't specifically need realpath for this (in my app), I used the following regex bodge
to delete the ../ and the preceeding folder from the string:
{
$path = eregi_replace("[^/]*/..?/","",$path);
}
Hope someone finds this useful!
Note: Before anyone asks why you'd have that dumb path in the first place, it's part of a
larger script that re-links HREFS in documents to be relative to the script's location not the
page. There's probably a much nicer way to achieve this, but what the hell.