<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: url code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 06 Oct 2008 07:55:21 GMT</pubDate>
    <description>DZone Snippets: url code</description>
    <item>
      <title>Canonical path</title>
      <link>http://snippets.dzone.com/posts/show/187</link>
      <description>This function transforms an HTTP request path (ie, $_SERVER['PATH_INFO']) into its canonical form, removing empty path elements and relative path elements (//, /./, /../). It assumes that there is a trailing slash on the path if it's a directory.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;function canonical_path($path) {&lt;br /&gt;    $canonical = preg_replace('|/\.?(?=/)|','',$path);&lt;br /&gt;    while (($collapsed = preg_replace('|/[^/]+/\.\./|','/',$canonical,1)) !== $canonical) {&lt;br /&gt;        $canonical = $collapsed;&lt;br /&gt;    }&lt;br /&gt;    $canonical = preg_replace('|^/\.\./|','/',$canonical);&lt;br /&gt;    return $canonical;&lt;br /&gt;}&lt;/code&gt;</description>
      <pubDate>Sun, 17 Apr 2005 08:59:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/187</guid>
      <author>adrian (Adrian Sampson)</author>
    </item>
  </channel>
</rss>
