Home  >  Article  >  Backend Development  >  How to determine whether it is a string in php

How to determine whether it is a string in php

藏色散人
藏色散人Original
2020-08-11 09:06:598089browse

In PHP, you can use the "is_string" function to determine whether a variable is a string. It can be understood that this function only detects the type. Even if a variable is empty, as long as it is a string type, it will return true. Its usage syntax is "bool is_string (mixed $var)".

How to determine whether it is a string in php

Recommended: "PHP Video Tutorial"

is_string() detects whether the variable is of string type and returns the value Is true or false. It can be understood here that it only detects the type. Even if a variable is empty, it will return true as long as it is a string type.

PHP version requirements: PHP 4, PHP 5, PHP 7

Syntax

bool is_string ( mixed $var )

Parameter description:

$var: Variable to be detected.

Return value

If the specified variable is a string, TRUE is returned, otherwise FALSE is returned.

Example

<?php
if (is_string("2663"))
    echo &#39;这是一个字符串。&#39; . PHP_EOL;
else
    echo &#39;这不是一个字符串。&#39;;
var_dump(is_string(&#39;XYZ&#39;));
var_dump(is_string("99"));
var_dump(is_string(123.05));
var_dump(is_string(false));
?>

The output result is:

This is a string.

bool(true)
bool(true)
bool(false)
bool(false)

The above is the detailed content of How to determine whether it is a string in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn