-5

大家好,我有这个问题我无法比较这两个字符串

<?php
 $dir = '/var/www/devData/test';

 // create new directory with 777 permissions if it does not exist yet
 // owner will be the user/group the PHP script is run under
 if ( !file_exists($dir) ) {
  mkdir ($dir, 0777);
 }



         $flag = 0;
         $stringData = $_POST['data']; // echo = null
         $file = "/var/www/devData/test/ciao.txt"; 
         $fh = fopen($file, 'a+') or die("can't open file");

         while(!feof($fh)) {
                    $theData = fgets($fh, filesize($file));
                    array_push($arr,$theData);
                    $i++;
         }  
         for($j=0; $j<count($arr); $j++) 
         if($stringData == $arr[j]){ // is the problem 
            $flag = 1;
         }
         if($flag = 0){
            fwrite($fh, $stringData); // fwrite works perfectly even if i try to print $string the result is null 
         }
         fclose($fh); 



 ?>

有人可以解释我如何解决这个问题?这个脚本的目标是避免用户写两次相同的东西

4

1 回答 1

2
     if($stringData == $arr[j]){ // is the problem 
                           ^^^
                      is missing a $

激活错误报告,这应该会自动向您指出:

error_reporting(E_ALL);
ini_set('display_errors', true);
于 2012-08-01T10:24:33.137 回答