douwen4401
douwen4401
2013-11-26 15:15

PHP +发出file_get_contents并比较值

已采纳

This is driving me nuts. I have a test.html file that contains either "OPEN" or "CLOSED" inside of it. I do a file_get_contents():

$testA = file_get_contents ('files/test.html');

if ($testA == 'OPEN') {
  $color1 = '#00800';
  $back1 = '#DDFFDD';                        
}
else {
  $color1 = '#FF0000';
  $back1 = '#FFD9CC';                        
}

It returns false even if the value in my test.html = OPEN.

Using $testA = "OPEN"; works just fine. I'm a newbie, so I know its something simple that I'm overlooking. Any help will be appreciated

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douzai6337 douzai6337 8年前

    Try this:

    $testA = file_get_contents ('files/test.html');
    
    if(strpos($testA, 'OPEN') !== FALSE){
        $color1 = '#00800';
        $back1 = '#DDFFDD';                        
    }else{
        $color1 = '#FF0000';
        $back1 = '#FFD9CC';                        
    }
    

    Edit You can read more about strpos() here.

    点赞 评论 复制链接分享

相关推荐