Quick newb question about .txt file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Quick newb question about .txt file

Post by MiniMonty »

Hi all,

just a quick one...

I have a .txt file which is pumping a single variable to a Flash front end.
I need a quick and dirty script to open the txt file which reads "&numReady=20",
subtract 1 from the digit, save with the string "&numReady=19" (18, 17, 16, etc.,) and close the file.

Any quick help on offer ?
I'm a newb but I know that if I had an hour I could work this out with a search or two - only I
don't have an hour - I have about 5 minutes 8O

Best wishes
Monty
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

How about a one-liner?

Code: Select all

file_put_contents('file.txt', '&numReady=' . strval(intval(substr(file_get_contents('file.txt'), 10)) - 1));
I guess I'm a little late, though.
Post Reply