• PHP Video Tutorials

PHP - is_resource() Function


Advertisements

Definition and Usage

The function is_resource() checks whether a variable is a resource.

Syntax

bool is_resource ( mixed $value )

Parameters

Sr.No Parameter & Description
1

value

The variable being evaluated.

Return Values

This function returns true if value is a resource, false otherwise. This function is not a strict type-checking method: it will return false if value is a resource variable that has been closed.

Dependencies

PHP 4 and above

Example

Following example demonstrates use of is_resource() function (Here test.txt is a dummy text file placed on the same path as this example file) −

<?php
   $file = fopen("test.txt","w");
   if (is_resource($file)) {
      echo "File is open";
   } else {
      echo "Error open file";
   }
?>

Output

This will produce following result −

File is open

Example

Following example demonstrates use of is_resource() function when resource is closed (Here test.txt is a dummy text file placed on the same path as this example file) −

<?php
   $file = fopen("test.txt","w");
   fclose($file);
   if (is_resource($file)) {
      echo "File is open";
   } else {
      echo "Error open file";
   }
?>

Output

This will produce following result −

Error open file
php_variable_handling_functions.htm

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements