当前位置: 首页> 函数类别大全> is_string

is_string

检测变量是否是字符串
名称:is_string
分类:变量处理
所属语言:php
一句话介绍:检查变量是否为字符串类型。

定义和用法

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 必需。指定要检查的变量。
同类函数
  • 释放给定的变量  unset

    unset

    释放给定的变量
  • 获取变量的字符串值  strval

    strval

    获取变量的字符串值
  • 检测变量是否是整数  is_int

    is_int

    检测变量是否是整数
  • 获取变量的布尔值  boolval

    boolval

    获取变量的布尔值
  • 获取变量的类型(可以为数组、字符串、匿名类和对象返回更有用的输出信息)  get_debug_type

    get_debug_type

    获取变量的类型(可以为数组、字符串、匿名
  • 验证变量的内容是否为可迭代值  is_iterable

    is_iterable

    验证变量的内容是否为可迭代值
  • 检测变量是否是一个标量  is_scalar

    is_scalar

    检测变量是否是一个标量
  • 检测参数是否为合法的可调用结构  is_callable

    is_callable

    检测参数是否为合法的可调用结构
热门文章