Results 1 to 2 of 2

Thread: Carriage Return Problem?

  1. #1
    Join Date
    Oct 2004

    Carriage Return Problem?

    I think this is a carriage return problem (or related), but I just can't seem to fix it.

    I have a <textarea> box into which I input and upload lists of products. It works. (Or seems to work until I try to search for and retrieve specific products).

    $list_items is my array, which I split out and add each item to it's own MySQL database field, one for each item. ie

    PHP Code:
    $listitems explode("\n"$list_items);
    while (list(
    $list_item) = each ($listitems)) {


    Trouble is, when I come to search for an item, I fail, except in two specific instances:

    First, my search function (not shown here) works when I overwrite the items directly in my MySQL database (phpMyAdmin). It successfully retrieves an item.

    The second (and the reason I think it may be a carriage return problem) instance when my search function works is when I search for an item which I know was the last item of an uploaded list. ie if I've uploaded a list of three products, when searching for the third item, my function will retrieve it, (no carriage return in it?), but not the first two.

    (Not that I can see any carriage returns in my database fields by the way.)

    I've tried adding the following into the routine above before anything is added to my database, but it's made no difference.

    PHP Code:
    $list_item str_replace("\r\n"""$list_item); 
    And now I'm out of ideas. (Software running on LAMP)

    Simon Duncan

  2. #2
    Join Date
    Aug 2004
    No guarantees, but I might use this instead of the explode():
    PHP Code:
    $listitems preg_split("[\r\n]+"trim($list_items)); 
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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