Results 1 to 3 of 3

Thread: Saving formatted text

  1. #1
    Join Date
    Mar 2012
    Posts
    3

    Saving formatted text

    I'm using textarea to make available a large blank area for freeform typing (it's a problem management app). The idea is to be able to paste in log messages and other output and save it in a mysql database for future searching.

    I'm using a 'text' field, 65k in size and using mysql_real_escape_string to process the text before putting it into the database.

    The problem is it's stripping out all the \n's. Taking out the mysql_real_escape_string function doesn't make a difference.

    Suggestions? I'd like to keep it searchable so turning it into a binary field isn't going to help (as far as I know anyway based on the mysql online docs).

    Thanks.

    Carl

  2. #2
    Join Date
    Mar 2012
    Posts
    3
    Ok, updated information after a lunchtime further search.

    There are a couple of good stackoverflow answers out there that I stumbled on.

    1. I use the javascript function, str.replace(/\n/g, '<br />'); to change the line feeds to html. Since the data is being passed as a GET, the line feeds are being lost. This converts it before being passed as a GET.

    When I redisplay the text in a table, it works great.

    2. I'm using a php function called br2nl which converts the <br /> entries to a \CR/LF. This outputs the data as a multi-line string.

    Unfortunately when the document.start.details.value has the string put in it, the CR/LF is lost and the output is a single line.

    So the mysql portion looks to be fixed, at least at the moment unless a better solution is found. Now I need to chase down how to maintain the CR/LF when put in a DOM value.

    Hmm, maybe instead of converting it in php, I should use the same javascript method to convert it back...

    Carl

  3. #3
    Join Date
    Mar 2012
    Posts
    3
    Hah, that did it.

    str = str.replace(/<br \//g, '\n');

    Solved.

    Carl

Posting Permissions

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