1. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    Here's what I want to do:
    I want to put a .txt-file containing a number on my server and then read it out with a php-script which will display it on the html-page and higher the number by one.

    send me all help to webmaster@jazzine.com
  2. #2
  3. No Profile Picture
    Paul Cotton
    Devshed Newbie (0 - 499 posts)
    Would you not just use fopen with the file name for reading the file and write back the number plus one.

    The code below works, I would use a server side include to pull it into the HTML
    (SSI in apache would be <!--#include file="readnum.php3"--> )

    Code is:

    $fp=fopen("num.txt","r+"); // open file
    $linein=fgets($fp,4096); // read first line = current number
    $linein=intval($linein); // convert to integer
    print "$linein"; // print it
    $linein++; // increment by one
    rewind($fp); // set pointer to start of file
    fputs($fp,$linein); // write the number back to the file
    fclose($fp); // close the file

Similar Threads

  1. C program to read from a data file into an array
    By rathornton in forum C Programming
    Replies: 4
    Last Post: March 16th, 2004, 11:23 AM
  2. Replies: 1
    Last Post: February 11th, 2004, 10:46 AM
  3. Possible to read in value from a text file?
    By discus18 in forum PHP Development
    Replies: 2
    Last Post: February 6th, 2004, 11:19 PM
  4. How to read multiple line text file into a variable
    By gatewaycityca in forum Visual Basic Programming
    Replies: 4
    Last Post: January 29th, 2004, 12:26 PM
  5. have file read contents of directory it is in?
    By thindery in forum PHP Development
    Replies: 1
    Last Post: January 24th, 2004, 11:18 PM

IMN logo majestic logo threadwatch logo seochat tools logo