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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts

    Textarea content to file

    I've been searching for this answer and I just can't get my head wrapped around some the posts that I have read.

    I have a textarea with this text:

    aaaa
    bbbb
    cccc
    dddd


    But when I write this data to a file it writes out like this:
    aaaabbbbccccdddd

    I've tried doing this but it doesn't work:
    PHP Code:
    $php_string0 str_replace("<br>","\n"$php_filedata); 
    Thanks for any help...!!!
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Hi there.

    I don't know if it is for any help, but this is the script I'm using to post data from a form to a .txt file:

    PHP Code:
    <?php
    $saving 
    $_REQUEST['saving'];
    if (
    $saving == 1){ 
    $data $_POST['data'];
    $file "auto_content/news.txt"

    $fp fopen($file"w") or die("Couldn't open $file for writing!");
    fwrite($fp$data) or die("Couldn't write values to file!"); 

    fclose($fp); 
    echo 
    "Saved to $file successfully!";

    }
    ?>
    <form name="add_news" method="post" action="add_news.php?saving=1" >
    <textarea name="data">
    </textarea>


    <input type="submit" value="Save">
    </form>
    Btw, wrong forum.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    But when I write this data to a file it writes out like this:
    aaaabbbbccccdddd
    Are you viewing the data directly from the file?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by abduraooft View Post
    Are you viewing the data directly from the file?
    Yes...
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by rfresh View Post
    Yes...
    this is not because you replace \r\n with ''?
    see that post:

    ereg_replace() Help

    the part about replacing with spaces not ''.

    best regards

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Quote Originally Posted by rfresh View Post
    Yes...
    You could use nl2br() function to retain the line breaks while displaying the content on a page.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by abduraooft View Post
    You could use nl2br() function to retain the line breaks while displaying the content on a page.
    this will not work because is no newlines in that file.

    best regards


  •  

    Posting Permissions

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