Mr P!nk Posted August 17, 2007 Share Posted August 17, 2007 hello ladies and gentlemen. i have a small problem of checking for duplicated unique data input. i want to know if its possible to write a php script which if i copy and paste an address book from one data source and save it , then update addresses from a different source it will say something along :- error $address already exists in this document. if so could someone point me in the right direction? thank you =] AA ** edit ** im not using MYSQL to store the data :-\ the server im doing this for doesn't support it "apparently" ??? Link to comment https://forums.phpfreaks.com/topic/65425-solved-check-for-duplicates/ Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 just check if the exists first! what do you have so far ? Link to comment https://forums.phpfreaks.com/topic/65425-solved-check-for-duplicates/#findComment-326704 Share on other sites More sharing options...
Mr P!nk Posted August 17, 2007 Author Share Posted August 17, 2007 <? $file = "shadow%00.txt"; if (file_exists($file)){ $file_content=file_get_contents($file); }else{ $cf = fopen($file, "w") or die("Error: file does not exist, and it can not be created.<BR>Please check permissions in the directory or create a file with coresponding name."); fputs($cf, ","); fclose($cf); } { if(strpos($file_content,"$address,")>0){die("Error: your address is already included in this list");} $cf = fopen($file, "a"); fputs($cf, "$address," ); fclose($cf); print "<p><span class=\"style5\">Thank you your data has been added to our database.<br /> Back to <a href=index.htm class=\"style5\">Acme Art.</a></span><span class=\"style7\"><br /> <br /> </span></p>"; } ?> this works fine for inputting the data one by one but when i add like 10 of the same addresses purposely they all go in to the .txt file with no error, then when i go to the distribution centre in the send to address box all those same addresses are there :-/. thanks Link to comment https://forums.phpfreaks.com/topic/65425-solved-check-for-duplicates/#findComment-326714 Share on other sites More sharing options...
Mr P!nk Posted August 17, 2007 Author Share Posted August 17, 2007 i have 6000+ addresses to input some maybe duplicated more than once and i don't have the time to scan/input them all individually. Link to comment https://forums.phpfreaks.com/topic/65425-solved-check-for-duplicates/#findComment-326717 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 this will remove the duplicates in one go will save to Newshadow%00.txt ie shadow%00.txt contains test1,test1,test1,test1,test1,test1,test1,test1,test1,test1,test2,test3,test3,test4,test5 new file test1,test2,test3,test4,test5 <?php $file = "shadow%00.txt"; if (file_exists($file)) { $file_content=file_get_contents($file); }else{ $cf = fopen($file, "w") or die("Error: file does not exist, and it can not be created.<BR>Please check permissions in the directory or create a file with coresponding name."); fputs($cf, ","); fclose($cf); } $tmp = explode(",", $file_content); $tmp = array_flip ( $tmp ); $tmp = array_flip ( $tmp ); $tmp = implode(",", $tmp); file_put_contents ( "New".$file, $tmp ); ?> Link to comment https://forums.phpfreaks.com/topic/65425-solved-check-for-duplicates/#findComment-326738 Share on other sites More sharing options...
Mr P!nk Posted August 17, 2007 Author Share Posted August 17, 2007 cheers for your help this is most appreciated. 1. i have this error Fatal error: Call to undefined function: file_put_contents() in /home/web/public_html/submail.php on line 45 file_put_contents ( "New".$file, $tmp ); Link to comment https://forums.phpfreaks.com/topic/65425-solved-check-for-duplicates/#findComment-326764 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 OK your running PHP4 not PHP5 try this <?php $file = "shadow%00.txt"; if (file_exists($file)) { $file_content=file_get_contents($file); }else{ $cf = fopen($file, "w") or die("Error: file does not exist, and it can not be created.<BR>Please check permissions in the directory or create a file with coresponding name."); fputs($cf, ","); fclose($cf); } $tmp = explode(",", $file_content); $tmp = array_flip ( $tmp ); $tmp = array_flip ( $tmp ); $tmp = implode(",", $tmp); //PHP5 only //file_put_contents ( "New".$file, $tmp ); //PHP 4 Safe if (!$handle = fopen("New".$file, 'a+')) { echo "Cannot open file New".$file; exit; } if (fwrite($handle, $tmp) === FALSE) { echo "Cannot write to file New".$file; exit; } fclose($handle); ?> Link to comment https://forums.phpfreaks.com/topic/65425-solved-check-for-duplicates/#findComment-326773 Share on other sites More sharing options...
Mr P!nk Posted August 17, 2007 Author Share Posted August 17, 2007 wow ok that's amazing. but i tried your test1,test1,test1,test1,test1,test1,test1,test1,test1,test1,test2,test3,test3,test4,test5 new file test1,test2,test3,test4,test5 but mine returned test1,test2,test3,test4,test5test1,test2,test3,test4,test5 any theory as to why? Im very close to loving you techie Thanks *** EDIT *** ah ive done it ;D i changed the if (!$handle = fopen("New".$file, 'a+')) to if (!$handle = fopen("New".$file, 'w+')) or am i just playing silly beggers? thanks for all your help madtechie. if i could kiss you i would . Link to comment https://forums.phpfreaks.com/topic/65425-solved-check-for-duplicates/#findComment-326799 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 LOL, correct fix i'll settle for clicking on the topic solved (bottom left) Link to comment https://forums.phpfreaks.com/topic/65425-solved-check-for-duplicates/#findComment-326814 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.