Resolving local URI's

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Howdy, I have a very simple problem, but it is causing me angst.
I hate "./".

When I see this:  <link href="./style.css" type="text/css"/> it makes
me twitch.

Why, oh why can it not be <link href="style.css" type="text/css"/>?
Preferable by far-- as any Grinch can see...

Many functions/methods/class can parse these uri's
but TO A ONE their spitshine output I despise
for the no-doubt rigid preset standard it complies
slithers 'mongst the file path, crossing t's and dotting i's
and in the home direct'ry hangs "./" above the threshold
indifferent to coders' surly growl that it's presence is undignified!

Seriously, what's up with that?  Is there some programmatic reason
that beginning relative URI's with "./" is preferable?

If I have a page located at:

And it outputs a HTML request for a global stylesheet that (for
logistical reasons) ends up looking like...

That's just extra-silly.  But every function I find that can resolve
local URI's to fix the 'up, then back down again' thing also insists
on putting the "./" in.

I could just hack around it and strip them off the front of addresses
I suppose but first I feel like I should ask-- is there a reason they
really ought to be there?


Re: Resolving local URI's

Derik wrote:
Quoted text here. Click to load it

None of this has ANYTHING to do with PHP.  I suggest you try alt.html.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Resolving local URI's

You can transform a path into its canonical representation using
Horde's Util::realPath below:

function realPath($path)
  /* Standardize on UNIX directory separators. */
  if (!strncasecmp(PHP_OS, 'WIN', 3)) {
    $path = str_replace('\', '/', $path);

  /* xx////xx -> xx/xx
   * xx/././xx -> xx/xx */
  $path = preg_replace(array("|/+|", "@(/\.)+(/|\Z(?!\n))@"),
array('/', '/'), $path);

  /* ./xx -> xx */
  if ($path != './') {
    $path = preg_replace("|^(\./)+|", '', $path);

  /* /../../xx -> xx */
  $path = preg_replace("|^/(\.\./?)+|", '/', $path);

  /* xx/ -> xx */
  if ($path != '/') {
    $path = preg_replace("|/\Z(?!\n)|", '', $path);

  /* /xx/.. -> / */
  while (strpos($path, '/..') !== false) {
    $path = preg_replace("|/[^/]+/\.\.|", '', $path);

  return empty($path) ? '/' : $path;}
Line 527


John Peters

Quoted text here. Click to load it

Re: Resolving local URI's

Derik a écrit :
Quoted text here. Click to load it

Regarding programmation, and PHP, yes. "./" force you to be on the local
server, to execute scripts locally. Which is a must have when you deal
with scripts turning on your server and not on client's side.

Regarding HTML... well I would say a very good practice, you'd better
use it everywhere rather than forget it.  Plus it makes the code
clearer, as you specifically request the current folder, while no "./"
can sometimes just means you forgot it. Also it's easier to change if
you ever have to move the directory. a global replace of "./" by
"./newdir" is easy, while replacing "nothing" isn't.


Site Timeline