Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php

What is the is_readable() function in PHP?

Behzad Ahmad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The is_readable() function in PHP checks whether the given filename is readable.

For the function to label a defined path as readable, the file must both exist and be readable.

Syntax

is_readable(string: $name):bool

Parameters

name: This is the path of the file we want to check.

Return value

is_readable() returns true if the provided path of the file exists and the file is readable. Otherwise, in case of any error, it returns false.

Code

The code below shows how to use the is_readable() function.

main.php
q2.txt
<?php
$file1 = "q2.txt";
if(is_readable($file1))
{
echo ("q2 is readable");
}
else
{
echo ("q2 is not readable");
}
?>

Explanation

A file q2.txt is created and passed to the is_readable function. Since the file exists and is readable, it returns true and the above output is produced.

This function produces cache output. So, in order to clear the cache, we invoke the clearstatcache() function.

RELATED TAGS

php

CONTRIBUTOR

Behzad Ahmad
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring