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”
这就是他做错的地方,是的。