Reputation: 456
Well, I have a text file that constantly changes. The part of the text file is this important line:
e=username
The username part of it changes constantly, but I need to capture the username
part of e=username
string and put it into a variable every time it changes. Problem is I don't know how to. The file name is replace.txt
Upvotes: 0
Views: 149
Reputation: 138447
filemtime()
returns the time the file was last modified. Poll this timestamp every so often and read the file to check for a new e=username
entry if the timestamp is later than the previous time you checked.
The timestamp is given in seconds, so there's no point checking it more than once a second. If you need more frequent updates, you'll have to read the file continuously as the last modified time is stored with second accuracy.
To extract username
from e=username
, you can use preg_match()
:
if (preg_match("/^e=(.+)$/", "e=username", $matches))
print $matches[1];
Upvotes: 4