PHP读取文件并检查是否存在某个字符串

时间:2015-10-09 01:12:06

标签: php

到目前为止,这就是我所拥有的,但它似乎并没有起作用......

    <?
    $file = fopen('wiu.dat','r')
    while (wui = fgets($file)){
    if ($wui = 'True') {
      header("Location: index.html");
      die()
    } else {
      echo"<h2>Down for maintenance.</h2>"
    ;}}
    fclose($fh);
    ?>

非常感谢任何反馈

1 个答案:

答案 0 :(得分:3)

我解决了明显的问题。我在第一行之后和die()后添加了分号,在wui条件下将$wui更改为while,将$wui = 'True'更改为$wui == 'True',已将fclose($fh);更改为fclose($file);并清理了您的缩进,以便它看起来更好。从那里开始,我想代码的成功取决于你在wiu.dat内的内容。

<?php
  $file = fopen('wiu.dat','r');
  while ($wui = fgets($file)) {
    if ($wui == 'True') {
      header("Location: index.html");
      die();
    } else {
      echo"<h2>Down for maintenance.</h2>";
    }
  }
  fclose($file);
?>