Hey Matt, Thanks for replying. > > <?php > > > > $url='http://www.textx.com/t1/t2/t3/blah.html'; > > > > function ret_url($rel_path, $base = '') > > { > > $base_path = substr($base, 0, strpos($base, > '/',7)); > > > > if(substr($rel_path,0,1)=='/' && > > !strpos($rel_path,'/../')) > > { return $base_path.$rel_path; } > > > > elseif(strpos($rel_path,'://') > 0) > > { return $rel_path; } > > > > else { return > > collapse(dirname($base).'/'.$rel_path); } > > > > return $rel_path; > > } > > > > /* this function removes the /../ parts */ > > function collapse($path) > > { > > > > while(strpos($path,'/../') !== false) > > {$p2 = ereg_replace('/([^/]*)/\.\./','/',$path); > > if($p2==$path) > > break; > > $path = $p2; > > } > > > > return $path; > > } > > > > $uris = array(); > > $uris[] = '/blah.jpg'; > > $uris[] ='/imgs/blah.jpg'; > > $uris[] ='imgs/blah.jpg'; > > $uris[] ='../imgs/blah.jpg'; > > $uris[] ='/../imgs/blah.jpg'; // ## not working > ## > > $uris[] ='/../../imgs/blah.jpg'; // ## not working > ## > > $uris[] > ='http://some-site-blah.com/imgs/blah.jpg'; > > > > echo '<table border=1>'; > > foreach($uris as $uri) > > { > > echo '<tr><td>'.htmlspecialchars($uri).'</ > > > td><td>'.htmlspecialchars(ret_url($uri,$url)).'</td></tr>'; > > } > > echo '</table>'; > > ?> > try this: > > function ret_url($rel_path, $base = '') > { > $base_path = substr($base, 0, strpos($base, '/',7)); > > if(substr($rel_path,0,1)=='/' && > strpos($rel_path,'/../') === false) > { return $base_path.$rel_path; } > > elseif(strpos($rel_path,'://') > 0) > { return $rel_path; } > > else { return > collapse(dirname($base).'/'.$rel_path); } > > return $rel_path; > } Close, but its not giving the correct paths. eg: /../imgs/blah.jpg should return http://www.textx.com/t1/t2/imgs/blah.jpg but its returning: http://www.textx.com/t1/t2/t3/imgs/blah.jpg and this: /../../imgs/blah.jpg should return: http://www.textx.com/t1/imgs/blah.jpg but its returning: http://www.textx.com/t1/t2/imgs/blah.jpg in both cases one extra level directory :-( Any ideas? Thanks, Mag ===== ------ - The faulty interface lies between the chair and the keyboard. - Creativity is great, but plagiarism is faster! - Smile, everyone loves a moron. :-) _______________________________ Do you Yahoo!? Declare Yourself - Register online to vote today! http://vote.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php