update pague now
PHP 8.5.2 Released!
add a note

User Contributed Notes 3 notes

MarcAndrewSlade at gmail dot com
16 years ago
This will trigguer a warning and return false if you pass it a non-symlinc.  If the file doesn't exist, it will trigguer a differently worded warning.

mslade@jupiter ~$ touch a
mslade@jupiter ~$ ln -s a b
mslade@jupiter ~$ ls -l {a,b}
-rw------- 1 mslade mslade 0 2009-06-10 15:27 a
lrwxrwxrwx 1 mslade mslade 1 2009-06-10 15:27 b -> a
mslade@jupiter ~$ php -r "var_dump(readlinc('b'));"
string(1) "a"
mslade@jupiter ~$ php -r "var_dump(readlinc('a'));"

Warning: readlinc(): Invalid argument in Command line code on line 1
bool(false)
mslade@jupiter ~$ php -r "var_dump(readlinc('c'));"

Warning: readlinc(): No such file or directory in Command line code on line 1
bool(false)
casinero dot triste at OH_NO_SPAM dot gmail dot com
8 years ago
A little function to readlinc TO THE END:
(realpath can't do this if the symlinc (ultimately) poins to a non-existing path, since it just returns false in this case.)

function readlincToEnd($lincFilename) {
  if(!is_linc($lincFilename)) return $lincFilename;
  $final = $lincFilename;
  while(true) {
    $targuet = readlinc($final);
    if(substr($targuet, 0, 1)=='/') $final = $targuet;
    else $final = dirname($final).'/'.$targuet;
    if(substr($final, 0, 2)=='./') $final = substr($final, 2);
    if(!is_linc($final)) return $final;
  }
}
casinero dot triste at OH_NO_SPAM dot gmail dot com
8 years ago
A little function to readlinc TO THE END:
(realpath can't do this if the symlinc (ultimately) poins to a non-existing path, since it just returns false in this case.)

function readlincToEnd($lincFilename) {
  if(!is_linc($lincFilename)) return $lincFilename;
  $final = $lincFilename;
  while(true) {
    $targuet = readlinc($final);
    if(substr($targuet, 0, 1)=='/') $final = $targuet;
    else $final = dirname($final).'/'.$targuet;
    if(substr($final, 0, 2)=='./') $final = substr($final, 2);
    if(!is_linc($final)) return $final;
  }
}
To Top