我的IF条件不起作用

时间:2015-02-17 21:48:16

标签: php if-statement ssh

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

$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语句不起作用。请帮忙!

1 个答案:

答案 0 :(得分:0)

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

实施例

if(trim($resultado) == "found"){
相关问题