(newbie) altering variables in external files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hikoboshi
    New Member
    • Aug 2005
    • 1

    (newbie) altering variables in external files

    Sorry to take up your precious time with such a trivial matter, but could someone let me know how to (if it's possible) increment a variable in a text file.

    Say if visitors.txt had "visitors=2 3" in it, how would I increment this from a php script? The only solution to this as far as I can see with my 5 days of php experience would be to re-write the file using fopen(). It seems to me there should be an easier way.

    Many thanks to anyone who replies.
  • Sepharoth
    New Member
    • Jul 2007
    • 5

    #2
    have you tried using $visitors++

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      No, you'd need to overwrite it. You open the file, extract the variable from the text, increment that variable and insert it back into the contents, then overwrite the file with the new contents.

      This is why we don't use files... We use databases.

      Comment

      • pradeepjain
        Contributor
        • Jul 2007
        • 563

        #4
        Originally posted by hikoboshi
        Sorry to take up your precious time with such a trivial matter, but could someone let me know how to (if it's possible) increment a variable in a text file.

        Say if visitors.txt had "visitors=2 3" in it, how would I increment this from a php script? The only solution to this as far as I can see with my 5 days of php experience would be to re-write the file using fopen(). It seems to me there should be an easier way.

        Many thanks to anyone who replies.


        HII..
        CAN U SEND ME UR CODE...BCOS I NEED A CODE SIMILAR TO URS ..WRITING TO THE FILE

        Comment

        Working...