Hello. i have this script bellow wich reads a .txt file and get's it's contents into my .php and i wanted to ask if it's possible to make and mysql entry each time a specific line changes in the txt? in the TXT is this line "Name: p3403_dpdp-ii TIP3P ff96" is it somehow possible to make an mysql entry into my database as soon as it changes to someting else? like if i want it to place a count of 1 into the database table each time so i could for example se how many time in total it has changed. <?php $file = fopen("myfile.txt", "r") or exit("Cannot to open file!"); //Read a line of the file until found what you are looking for while(!feof($file)) { echo fgets($file). "<br />"; } fclose($file); ?> PHP:
sure. just a simple pattern match against the contents of the file. <?php $file = "mytext.txt"; if (file_exists($file)) { $fh = fopen($file,"r"); $data = fread( $fh, filesize($file) ); } if(!preg_match("/name: p3403_dpdp-ii tip3p ff96/i",$data)) { // it changed do sql insert here. } else { return; // it didn't change } ?> PHP:
hey ansi and thanks, now my question is that if the name that changed does a mysql entry, and later the new name that replaced "p3403_dpdp-ii tip3p ff96" changes again, how will that be recorded into the database?
store the string inside the database and select it before doing the pattern match and then match against that. if it has changed, update the rows you want on you database and then update the keyword in there as well so next time it is searching for the new string instead of the old. hope this helped some.