Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果字符串为空,则执行以下操作_Php - Fatal编程技术网

Php 如果字符串为空,则执行以下操作

Php 如果字符串为空,则执行以下操作,php,Php,我很难让一个空字符串包含一些内容,我还从该字符串中删除了一些其他不必要的字符 $desc = strip_tags($mapAnnotationArray); $mapAnnotationArrayOutput = str_replace( array('"', '(' , ')'), '', $desc); $mapAnnotationArrayOutput = trim($mapAnnotationArrayOutput); if(empty($mapAnnotationArrayOut

我很难让一个空字符串包含一些内容,我还从该字符串中删除了一些其他不必要的字符

$desc = strip_tags($mapAnnotationArray);

$mapAnnotationArrayOutput = str_replace( array('"', '(' , ')'), '', $desc);
$mapAnnotationArrayOutput = trim($mapAnnotationArrayOutput);

if(empty($mapAnnotationArrayOutput)) {
    ($mapAnnotationArrayOutput == "empty");
}
试着放:

print("String is empty");
在if语句中,此时
($mapAnnotationArrayOutput==“empty”)
将没有输出,因此您不知道字符串是否为空

如果试图将变量的值指定为“空”,请使用:

$mapAnnotationArrayOutput=“empty”


相反。

我看到很多人写:

if( x = "foo")
想知道为什么它会将
“foo”
分配给
x
。。。但决不能反过来

if( !$mapAnnotationArrayOutput) $mapAnnotationArrayOutput = "empty";
改变这个

($mapAnnotationArrayOutput == "empty");
对此

$mapAnnotationArrayOutput = "empty";

什么是
($mapAnnotationArrayOutput==“空”)打算做什么?赋值是用一个等号完成的。您正在比较而不是赋值,这很可能是您打算做的。使用
($mapAnnotationArrayOutput=“empty”)
@EM创建其进入数据库如果变量
$mapAnnotationArrayOutput
进入数据库,请使用
$mapAnnotationArrayOutput=“empty”
而不是
$mapAnnotationArrayOutput==“empty”
这就是他做错的地方,是的。