大家好,我有这个问题我无法比较这两个字符串
<?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);
?>
有人可以解释我如何解决这个问题?这个脚本的目标是避免用户写两次相同的东西