• PHP Video Tutorials

PHP - is_string() Function



Definition and Usage

The function is_string() verifies whether the type of a variable is string.

Syntax

bool is_string ( mixed $value )

Parameters

Sr.No Parameter & Description
1

value

The variable being evaluated.

Return Values

This function returns true if value is a string, false otherwise. This function does not consider NULL to be scalar.

Dependencies

PHP 4 and above

Example

Following example demonstrates use of function is_string() −

<?php
   $a = "Tutorialspoint";
   echo "a is ".( is_string($a)? 'string' : 'not string') . "<br>";

   $b = 0;
   echo "b is ".( is_string($b)? 'string' : 'not string') . "<br>";

   $c = 40;
   echo "c is ".( is_string($c)? 'string' : 'not string') . "<br>";

   $d = NULL;
   echo "d is ".( is_string($d)? 'string' : 'not string') . "<br>";

   $e = array("a", "b", "c");
   echo "e is ".( is_string($e)? 'string' : 'not string') . "<br>";

   $f = 3.1416;
   echo "f is ".( is_string($f)? 'string' : 'not string') . "<br>";

   $g = new stdClass();
   echo "g is ".( is_string($g)? 'string' : 'not string') . "<br>";

   $h = '';
   echo "h is ".( is_string($h)? 'string' : 'not string') . "<br>";
?>

Output

This will produce following result −

a is string
b is not string
c is not string
d is not string
e is not string
f is not string
g is not string
h is string
php_variable_handling_functions.htm
Advertisements