我的IF条件是';t工作


My IF condition isn't working

我有个问题。这是我的代码:

$resultado=$ssh->exec('[ -d /usr/share/servermanager/backups/  ] && echo "found" || echo "not_found" '); 
        //die ($resultado);
            if($resultado == "found"){
                $alert_inst='<span class="label label-success mr10 mt10" >Instalado</span>';
            }else{
                $alert_inst='<span class="label label-danger mr10 mt10" >Não instalado</span>';   
            }

当我取消注释die()时,它会打印出来:

found

但是if语句不起作用。请帮忙!

在从$ssh->exec返回的字符串中,found之前或之后可能还有一些额外的空白。在比较$resultado变量之前,请对其使用trim

示例:

if(trim($resultado) == "found"){