• PHP Video Tutorials

PHP - is_string() Function


Advertisements

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

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