Linux 拨号vps windows公众号手机端

php如何判断字符串是否为空

lewis 7年前 (2018-03-13) 阅读数 12 #程序编程
文章标签 PHP

在PHP中,可以使用empty()函数和strlen()函数来判断字符串是否为空。

  1. 使用empty()函数:
$str = "hello";
if (empty($str)) {
    echo "String is empty";
} else {
    echo "String is not empty";
}

如果字符串为空,empty()函数会返回true,否则返回false

  1. 使用strlen()函数:
$str = "hello";
if (strlen($str) == 0) {
    echo "String is empty";
} else {
    echo "String is not empty";
}

strlen()函数会返回字符串的长度,如果长度为0,则字符串为空。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门