PHP Function Reference

PHP is_link() Function



The PHP is_link() function checks whether the given filename is a symbolic link.

Note: The results of this function are cached. Use clearstatcache() function to clear the cache.

Syntax

is_link(filename)

Parameters

filename Required. Specify the path to the file to check.

Return Value

Returns true if the filename exists and is a symbolic link, otherwise returns false.

Exceptions

Upon failure, an E_WARNING is thrown.

Example:

Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to check whether the given filename is a symbolic link.

<?php
$target = 'test.txt';
$link1 = 'sampleTest';
$link2 = 'sampleDemo.ttx';

//creating a symbolic link
symlink($target, $link1);

//creating a hard link
link($target, $link2);

//checking if $target exists and is a symbolic link
if(is_link($target)) {
  echo "$target is a symbolic link.\n";
} else {
  echo "$target is not a symbolic link.\n";
}

//checking if $link1 exists and is a symbolic link
if(is_link($link1)) {
  echo "$link1 is a symbolic link.\n";
} else {
  echo "$link1 is not a symbolic link.\n";
}

//checking if $link2 exists and is a symbolic link
if(is_link($link2)) {
  echo "$link2 is a symbolic link.\n";
} else {
  echo "$link2 is not a symbolic link.\n";
}
?>

The output of the above code will be:

test.txt is not a symbolic link.
sampleTest is a symbolic link.
sampleDemo.ttx is not a symbolic link.

❮ PHP Filesystem Reference