In PHP, you can use the is_string() function to determine whether a variable is a string, the syntax is "is_string ($var)"; if the specified variable is a string, TRUE is returned, otherwise FALSE is returned.
The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer
is_string() function is used to detect whether the variable is String. Syntax format:
bool is_string ( mixed $var )
Parameter description:
$var: variable to be detected.
PHP version requirements: PHP 4, PHP 5, PHP 7
Return value: If the specified variable is a string, then Returns TRUE, otherwise returns FALSE.
Example: is_string() function determines whether a variable is a string
<?php header("Content-type:text/html;charset=utf-8"); $a=123; var_dump($a); var_dump(is_string($a)); if (is_string($a)){ echo "这是一个字符串。". "<br>"; } else{ echo "这不是一个字符串。". "<br>"; } $b="123"; var_dump($b); var_dump(is_string($b)); if (is_string($b)){ echo "这是一个字符串。". "<br>"; } else{ echo "这不是一个字符串。". "<br>"; } ?>
Output result:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine if a variable is a string in php. For more information, please follow other related articles on the PHP Chinese website!