Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP trim help!

Options
  • 11-10-2001 10:47pm
    #1
    Closed Accounts Posts: 59 ✭✭


    Could someone tell me how to get rid of the end of line (\n) when reading from an external .txt file ?


    I think it should go something like this:

    <?
    $file_dir = 'path/to';
    $text = file("$file_dir/file.txt");
    $textline = $text[0];
    $trimmed = rtrim($textline);

    echo $trimmed;
    ?>

    ...unfortunately I'm getting an error.



    Thanks in advance,
    Peter.


Comments

  • Registered Users Posts: 1,562 ✭✭✭Snaga


    I used............................

    <?
    $file_path = 'test.txt';
    $text = file("$file_path");
    $textline = $text[0];
    $trimmed = rtrim($textline);

    echo $trimmed;
    ?>


    This works fine for me where the text file is as follows(in the same directory as the php script)

    --> cat test.txt
    blah
    blah2
    blah3

    It outputs 'blah' as it should.


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    There's nothing wrong with your code Peter, apart from verbosity:

    [PHP]
    <?
    $t = file('path/to/file.txt');
    echo rtrim($t[0]);
    ?>
    [/PHP]

    What's the error?

    adam


Advertisement