Current Location: Home> Function Categories> is_string

is_string

Detect whether a variable is a string
Name:is_string
Category:Variable processing
Programming Language:php
One-line Description:Checks whether the variable is of a string type.

Definition and usage

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

If the variable is of string type, this function returns true (1), otherwise false / no return value.

实例

检查变量是否为字符串类型:

<?php  
$a = "Hello";  
echo "a is " . (is_string($a) ? 'a string' : 'not a string') . "<br>";  
  
$b = 0;  
echo "b is " . (is_string($b) ? 'a string' : 'not a string') . "<br>";  
  
$c = 32;  
echo "c is " . (is_string($c) ? 'a string' : 'not a string') . "<br>";  
  
$d = "32";  
echo "d is " . (is_string($d) ? 'a string' : 'not a string') . "<br>";  
  
$e = true;  
echo "e is " . (is_string($e) ? 'a string' : 'not a string') . "<br>";  
  
$f = "null";  
echo "f is " . (is_string($f) ? 'a string' : 'not a string') . "<br>";  
  
$g = "";  
echo "g is " . (is_string($g) ? 'a string' : 'not a string') . "<br>";  
?>

亲自试一试

grammar

 is_string ( variable ) ;
parameter describe
variable Required. Specifies the variable to check.
Similar Functions
Popular Articles