Print a line from file to .php file.

Discussion in 'PHP' started by Mr Escobar, Nov 24, 2012.

  1. #1
    Hi.

    I have a file with unique information on each line, I want one line at a time to be printed to file.php with a 20min interval.

    ex info file.
    "abc
    def
    ghi
    jkl
    mno"

    So, for the first 20min i want "abc" to show in file.php, after 20min it should show "def" and after another 20min i want it to show "ghi", and so on..
    It doesnt matter if it reads from the info file or if I paste the contents to file.php and it reads from within itself, so to speak.
    Im sure this could be easily done, right?

    Anyone care to help out? I would be very greatful!
     
    Solved! View solution.
    Mr Escobar, Nov 24, 2012 IP
  2. #2
    If I understand correctly, You need some thing like this:

    file.php
    <?php
    
        $file = 'some.info'; // info-file
        $delay = 20*60; // Delay in seconds
        
        $info = file($file);
        $count = count($info);
        
        $key = time() % ($delay*$count);    
        print trim($info[(int)$key/$delay]);    
    
    ?>
    PHP:
     
    Sano000, Nov 25, 2012 IP