note 71334 added to function.realpath

From: Date: Thu, 23 Nov 2006 03:38:23 +0000
Subject: note 71334 added to function.realpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-120003@lists.php.net to get a copy of this message
Here's a function to canonicalize a URL containing relative paths. Ran into the problem when pulling links from a remote page. <?php function canonicalize($address) { $address = explode('/', $address); $keys = array_keys($address, '..'); foreach($keys AS $keypos => $key) { array_splice($address, $key - ($keypos * 2 + 1), 2); } $address = implode('/', $address); $address = str_replace('./', '', $address); } $url = 'http://www.example.com/something/../else'; echo canonicalize($url); //http://www.example.com/else ?> ---- Server IP: 216.194.113.175 Probable Submitter: 71.98.212.198 ---- Manual Page -- http://www.php.net/manual/en/function.realpath.php Edit -- https://master.php.net/note/edit/71334 Del: integrated -- https://master.php.net/note/delete/71334/integrated Del: useless -- https://master.php.net/note/delete/71334/useless Del: bad code -- https://master.php.net/note/delete/71334/bad+code Del: spam -- https://master.php.net/note/delete/71334/spam Del: non-english -- https://master.php.net/note/delete/71334/non-english Del: in docs -- https://master.php.net/note/delete/71334/in+docs Del: other reasons-- https://master.php.net/note/delete/71334 Reject -- https://master.php.net/note/reject/71334 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120003) next »