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

How to determine whether it is a string in php

藏色散人
Release: 2023-03-04 08:44:01
Original
8132 people have browsed it

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 )
Copy after login

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));
?>
Copy after login

The output result is:

This is a string.

bool(true)
bool(true)
bool(false)
bool(false)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template