PHP | is_link( ) Function

The is_link() function in PHP used to check whether the specified file is a symbolic link or not. The path to the file is sent as a parameter to the is_link() function and it returns TRUE if the filename exists and is a symbolic link, otherwise it returns FALSE.

Syntax:

is_link(file)

Parameters Used:
The is_link() function in PHP accepts only one parameter.



  • file : It is a mandatory parameter which specifies the path of the file.

Return Values:
It returns TRUE if the filename exists and is a symbolic link, otherwise it returns FALSE.

Exceptions:

  1. An E_WARNING is emitted on failure.
  2. The result of this function are cached and therefore the clearstatcache() function is used to clear the cache.

Examples:

Input : $mylink = "gfg";
        if(is_link($mylink))
        {
         echo ("$mylink is a symbolic link!");
        }
        else
        {
         echo ("$mylink is not a symbolic link!");
        }

Output : gfg is a symbolic link!

Input : $mylink = "gfg";
        if (is_link($mylink)) 
        {
         echo ("$mylink is a symbolic link!");
         echo "Reading the link :\n";
         echo(readlink($mylink));
        }
        else 
        {
         symlink("gfg", $mylink);
        }
Output : gfg is a symbolic link!
         Reading the link :
         A portal for geeks!

Below programs illustrate the is_link() function.

Program 1

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
$myfile = "gfg";
  
// checking whether the file is a symbolic link or not
if (is_link($mylink)) {
    echo ("$mylink is a symbolic link!");
} else {
    echo ("$mylink is not a symbolic link!");
}
  
?>

chevron_right


Output:

gfg is a symbolic link!

Program 2

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
$myfile = "gfg";
  
// checking whether the file
// is a symbolic link or not
if (is_link($mylink)) {
    echo ("$mylink is a symbolic link!");
  
    // Reading the link
    echo "Reading the link :\n";
    echo (readlink($mylink));
}
  
// creating a symbolic link of the
// file if it doesn't exist
else {
    symlink("gfg", $mylink);
}
  
?>

chevron_right


Output:

gfg is a symbolic link!
Reading the link :
A portal for geeks!

Reference:
http://php.net/manual/en/function.is-link.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.