请帮助 修改此代码不应重复n1 将数据输入文本文件时 使用
添加新邮件时,请勿重复文本
<?php
if(isset($_POST['send'])){
$n1 = trim($_POST['n1']);
$n2 = trim($_POST['n2']);
$fileLocation = getenv("DOCUMENT_ROOT") . "/te.txt";
$file = fopen($fileLocation,"a");
$n1 = $_POST['n1'];
$n2 = $_POST['n2'];
fwrite($file,$n1.'|'.$n2."\r\n");
fclose($file);
}
?>
答案 0 :(得分:0)
试试这个,
<?php
if(isset($_POST['send'])){
$n1 = trim($_POST['n1']);
$n2 = trim($_POST['n2']);
$fileLocation = getenv("DOCUMENT_ROOT") . "/te.txt";
$file = fopen($fileLocation,"r+");
$content = fread($file, filesize($fileLocation));
echo $content;
if(strstr($content, "|")){
fwrite($file,$n2."\r\n");
}else{
fwrite($file,$n1.'|'.$n2."\r\n");
}
fclose($file);
}
?>