PHP is_resource() Function
is_resource()This function is used to detect whether a variable is a resource type.
PHP Version Requirements: PHP 4, PHP 5, PHP 7
Syntax
bool is_resource ( mixed $var )
Parameter Description:
- $var: The variable to be detected.
Return Value
If the specified variable is of resource type, is_resource() returns TRUE, otherwise it returns FALSE.
Example
For the following example, you need to create a demo.txt file in the current directory.
Example
$fh = fopen('demo.txt','r');
if (is_resource($fh))
{
echo "File opened successfully...";
}
else
{
echo "Error opening file";
}
The output result is:
File opened successfully...Other Extensions