www.webdeveloper.com
Results 1 to 2 of 2

Thread: Carriage Return Problem?

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Posts
    63

    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)) {

    add_list_items($list_item);


    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
    Simon Duncan
    BusyView

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,925
    No guarantees, but I might use this instead of the explode():
    PHP Code:
    $listitems preg_split("[\r\n]+"trim($list_items)); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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



Recent Articles