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-26 13:48:225238browse

How to determine whether it is a string in PHP: You can use PHP's built-in function is_string() to determine. The is_string() function is used to detect whether a variable is a string. If the specified variable is a string, it returns true, otherwise it returns false.

How to determine whether it is a string in php

php provides us with the is_string() function, which is used to detect whether a variable is a string.

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

(Recommended video tutorial: php video tutorial)

Grammar:

bool is_string ( mixed $var )

(Recommended related tutorial: php graphic tutorial)

Implementation code:

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

Run result:

这是一个字符串。
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