English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP is_resource() function usage and example

PHP available functions

is_resource() The function is used to check if a variable is of resource type.

PHP version requirement: PHP 4, PHP 5, PHP 7

Syntax

bool is_resource ( mixed $var )

Parameter Description:

  • $var: The variable to be checked.

Return value

If the specified variable is of resource type, is_resource() returns TRUE, otherwise it returns FALSE.

Online Example

The following example requires you to create a demo.txt file in the current directory.

<?php
$fh = fopen('demo.txt','r');
if (is_resource($fh)) 
{
    echo "File opened successfully...";
}
else 
{
    echo "File opening error";
}
?>

The output is:

File opened successfully...

PHP available functions