找到你要的答案

Q:PHP Read file and check if a certain string exists

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

So far this is what I have, but it doesn't seem to be working...

    <?
    $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);
    ?>

Any feedback would be greatly appreciated

到目前为止,这是我所拥有的,但它似乎不工作…

    <?
    $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);
    ?>

任何反馈将不胜感激

answer1: 回答1:

I fixed the obvious problems. I added a semicolon after your first line and after die(), changed wui to $wui in your while condition, changed $wui = 'True' to $wui == 'True', changed fclose($fh); to fclose($file); and cleaned up your indentation just so it looks nicer. From there, I guess the success of the code depends on what you've got inside 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);
?>

我修正了明显的问题。我添加了一个分号后你的第一行和die()改变后,美元会在你会在的情况下,改变美元汇=“true”至汇= =“true”,改变了fclose($ FH);要关闭文件(文件);并清理你的压痕只是看起来更好。从那里,我猜码的成功取决于你在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);
?>
php