PHP is_string() 函数
定义和用法
is_string() 函数检查变量是否为字符串类型。
如果变量是字符串类型,则此函数返回 true (1),否则返回 false/无返回值。
实例
检查变量是否为字符串类型:
<?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>"; ?>
语法
is_string(variable);
| 参数 | 描述 |
|---|---|
| variable | 必需。指定要检查的变量。 |
技术细节
| 返回值: | 如果变量是字符串,则返回 TRUE,否则返回 FALSE。 |
|---|---|
| 返回类型: | 布尔值 |
| PHP 版本: | 4.0+ |