Jump to content

Getting part of content of a file


penguine
 Share

Recommended Posts

I am checking the file periodically.Can u give me the code to extract the data written after the previous modification ?eg:i wrote content "aaaaaaaaaakkkk" to file file.txt at 12.30 pm.So the modification time of file is 12.30pm.Again i wrote content "ddddddddddddddddddddddedddddddddd" to file file.txt at 12.34 pm.I need to extract the content betwwen 12.30pm and 12.34 pm.How do i do this?

Link to comment
Share on other sites

You need to keep a record in the database or somewhere static of the last things that you wrote in the file, and then you can use either strpos or strrpos to find the first or last occurance of the last thing you wrote (hopefully the next thing you wrote isn't the same), you can do the same thing to find the position of whatever you wrote next, and then everything else is between the end of the first part and the beginning of the second part.http://www.php.net/manual/en/function.strrpos.php

Link to comment
Share on other sites

You could also set a marker at the end of the file every time you see that it has changed.The next time you read the file, see if there is anything past the marker and write a new marker for next time.A Unix timestamp on its own line might make a good marker.Just make sure that the other script doesn't add the same marker... :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...