Results 1 to 8 of 8

Thread: return a single line from a text doc

Hybrid View

  1. #1
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: return a single line from a text doc

    Have a look at the file() function - it should help you

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  2. #2

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    Re: return a single line from a text doc

    ok i get what that function does but i dont get how to make it display only one line and that line being $line. how do i do this?
    If there is only one perfect person in the universe, does that make them imperfect?

  3. #3
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: return a single line from a text doc

    Quote Originally Posted by dandono
    ok i get what that function does but i dont get how to make it display only one line and that line being $line. how do i do this?

    Because the function returns the array, just pass the $line as the index to get the required line

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  4. #4

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    Re: return a single line from a text doc

    i think that this is not the best way to do this but it is the only way i can think. now somebody is going to come up with a code a houndred times better than mine in like five minuets.
    this is my code. i will set it to open a local text file in a bit.
    PHP Code:
    <?php
    // Get a file into an array.  In this example we'll go through HTTP to get 
    // the HTML source of a URL.
    $lines file('http://www.php.net/');
    $no $_GET['line'];

    // Loop through our array, show HTML source as HTML source; and line numbers too.
    foreach ($lines as $line_num => $line) {
    if (
    $line_num == $no)
    echo 
    "Line #<b>{$line_num}</b> : " htmlspecialchars($line) . "<br />\n";
    }

    // Another example, let's get a web page into a string.  See also file_get_contents().
    $html implode(''file('http://www.example.com/'));
    ?>
    thanks for the help
    If there is only one perfect person in the universe, does that make them imperfect?

  5. #5

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    Re: return a single line from a text doc

    how do you get that code to view a text doc on the server mechine like the path D:/blah.txt? is it just with fread?
    If there is only one perfect person in the universe, does that make them imperfect?

Posting Permissions

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



Click Here to Expand Forum to Full Width