<textarea> each lines as a separate record in php

Discussion in 'PHP' started by imnajam, Feb 4, 2008.

  1. #1
    Hi,

    I have a textarea in which I have say 10 lines, I want these 10 lines to be inserted as 10 records in database.
    I am looking for something like foreach lines in text area or something which I don't know.

    Anybody to help?

    Thanks in advance
     
    imnajam, Feb 4, 2008 IP
    bogart likes this.
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $lines = explode("\n", $_POST['textarea']);
    
    foreach ($lines AS $line)
    {
        $line = trim($line); // Removes possible carriage return characters (\r)
    
        // Do whatever with $line
    }
    
    PHP:
     
    nico_swd, Feb 4, 2008 IP
    imnajam likes this.
  3. imnajam

    imnajam Well-Known Member

    Messages:
    2,389
    Likes Received:
    113
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Excellent nico swd. Thank you:)
     
    imnajam, Feb 4, 2008 IP
  4. evil

    evil Well-Known Member

    Messages:
    588
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    108
    #4
    thank you
    just what I was looking for :)
     
    evil, Feb 12, 2008 IP