www.webdeveloper.com
Results 1 to 3 of 3

Thread: UNIX-commands in PHP code?

  1. #1
    Join Date
    Jul 2006
    Location
    Sweden
    Posts
    190

    UNIX-commands in PHP code?

    Hi,

    I have a task to use the UNIX-command tail -10 and read ten rows from a .txt file. This is new for me and I need some help with the code and how it's working?

    I have search some and discovered the exec() and want to use this, but how do I read the rows from the .txt file?

    Preciate some help! Thanks!

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,922
    See shell_exec().
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Feb 2005
    Posts
    42
    No need to do that:
    Code:
    <?php
    $myfile = 'test.txt';
    $lines = file($myfile);   
    $x = count($lines);
    for($i=$x;$x-10;$i--){
        echo $lines[$i];
    }
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles