How to fread() starting from a certain line?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to fread() starting from a certain line?

    Hello Guys.

    I get a lot of server hangs and exceed max_connections, so i wanted to try reducing the load by using a .txt file.
    Do you know if it's possible to read a file starting from a certain line? e.g if i want to read a file starting from line 10 ending at line 15? on a db it's
    PHP Code:
    $mysqli->query("SELECT * FROM `table` LIMIT 10, 5"
    Now can the same results be achieved reading a txt file?
    libra.wen.ru

    #2
    maybe like this
    PHP Code:
    function myfread($file$start 1$end false){
        
    $content '';
        
    $data file($file);
        for(
    $i = ($start-1); $i < ($end $end count($data)); $i++)
            
    $content .= $data[$i];
        return 
    $content;
    }


    echo 
    myfread("test.txt",2,5)." - ";
    echo 
    myfread("test.txt",4)." - ";
    echo 
    myfread("test.txt")." - "

    Comment


      #3
      PHP Code:
      <?php

      $f 
      fopen('myfile.txt''r');
      $lineNo 0;
      $startLine 3;
      $endLine 6;
      while (
      $line fgets($f)) {
          
      $lineNo++;
          if (
      $lineNo >= $startLine) {
              echo 
      $line;
          }
          if (
      $lineNo == $endLine) {
              break;
          }
      }
      fclose($f);

      ?>
      Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

      Comment


        #4
        why dont you use SQLite or Doctrine 2

        Comment

        Working...
        X