Zyse Posted February 18, 2010 Share Posted February 18, 2010 Im trying to learn how to place a read file line by line and prevent duplicate entries and also BLANK entries, into my process php script, using feof, I have failed many times and get so many errors such as syntax expecting . or , and so forth this is my process.php <?php $File = "links.txt"; $Handle = fopen($File, 'a'); $Data = "".$_POST['ID']; fwrite($Handle, $Data."\n"); print "Data Added\n"; fclose($Handle); ?> <?php countLines("links.txt"); function countLines($filepath) { $handle = fopen( $filepath, "r" ); $count = 0; while( fgets($handle) ) { $count++; } fclose($handle); return $count; } ?> <head> <meta http-equiv="REFRESH" content="5;test1.php"></HEAD> <br> please wait... navigating back! I got fed up and deleted all my work, to start from scratch, if feof($_POST['ID']) { alert 'Already entered'; return; } that was just one of my attempts also im unsure if putting in /n would make it look for /n or new line, if it looks for new line and every file has the new line marker would it always return as the data was already entered? Thanks in advance for assistance/teaching! Link to comment https://forums.phpfreaks.com/topic/192485-preventing-blank-or-already-entered-values/ Share on other sites More sharing options...
Zyse Posted February 18, 2010 Author Share Posted February 18, 2010 would fgets be the best way to go about this? Link to comment https://forums.phpfreaks.com/topic/192485-preventing-blank-or-already-entered-values/#findComment-1014481 Share on other sites More sharing options...
sader Posted February 18, 2010 Share Posted February 18, 2010 $lines = file("file.txt", 1); $lines[] = "new string"; file_put_contents("file.txt', implode(PHP_EOL, array_unique($lines)), FILE_USE_INCLUDE_PATH); Link to comment https://forums.phpfreaks.com/topic/192485-preventing-blank-or-already-entered-values/#findComment-1014483 Share on other sites More sharing options...
Zyse Posted February 18, 2010 Author Share Posted February 18, 2010 I thanks you for your reply, but Im not quite understanding, if you could teach the context you were using and where it would be placed, :3 Link to comment https://forums.phpfreaks.com/topic/192485-preventing-blank-or-already-entered-values/#findComment-1014524 Share on other sites More sharing options...
Zyse Posted February 19, 2010 Author Share Posted February 19, 2010 still stewing over retarded code, with no new leads on a solution. Link to comment https://forums.phpfreaks.com/topic/192485-preventing-blank-or-already-entered-values/#findComment-1014693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.