Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation how to write a loop for coping all line between two lines from a text file

    Hi

    Can any one let me know how to write a loop for coping all line between two lines from a text file.

    The start line is

    |Websoftexpert | | |


    and the end line is


    |--------------------------------------------------------------------------------------------------------------------------------|


    Any sugesstion or code?

    thanks in advance

    akash sinha
    websoftexpert@yahoo.com
    http://akash.biz/

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    This should work:
    PHP Code:
    <?php
    $file 
    'file.txt';
    $start '|Websoftexpert | | |';
    $end '|--------------------------------------------------------------------------------------------------------------------------------|';
    if(
    file_exists($file) && is_file($file))
    {
        
    $handle fopen($file'r');
        
    $ret = array();
        
    $read false;
        while(!
    feof($handle))
        {
            
    $data fgets($file);
            if(
    trim($data) != $start)
            {
                
    $read true;
                continue;
            }
            if(
    trim($data) == $end && $read == true)
            {
                
    $read false;
                break;
            }
            
    $ret[] = $data;
        }
    }
    var_dump($ret);
    ?>
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •