How do I avoid INSERTING blank or empty lines from a textarea?
<p>i need help in removing extra line that was created after pasting a value in my textarea, </p>

<p>this code works okay but if there is a blank line added in my textarea its also uploading it into my db, which inturn messed up my db coz its missing the primary key (ars_no) entry so i cant delete it...i need to remove the extra line prior to uploading to db, i tried to use the code below to no avail:</p>

<pre><code>function removeEmptyLines($RemedyTicketNo)
{
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $RemedyTicketNo);
}
</code></pre>

<p>here is my code to INSERT to db:</p>

<pre><code>require 'include/DB_Open.php';

    if(isset($_POST['DBLoad']))
{
    //print_r($_POST);
    //die();
    $Category2 = $_POST['Category2'];
    $Category3 = $_POST['Category3'];
    $Status = $_POST['Status'];
    $Date = $_POST['Date'];
    $Severity = $_POST['Severity'];
    $BanType = $_POST['BanType'];
    $XiD = $_POST['XiD'];
    $Ticket = $_POST['Ticket'];

    //Process the input textareas into arrays
    $PhoneNumber = array_map('mysql_real_escape_string', explode("\r\n", $_POST['PhoneNumber']));
    $Createdate = array_map('mysql_real_escape_string', explode("\r\n", $_POST['Createdate']));
    $RemedyTicketNo = array_map('mysql_real_escape_string', explode("\r\n", $_POST['PhoneNumber']));

    //Determine the values with the least amoutn of elements
    $min_count = min(count($PhoneNumber), count($Createdate), count($RemedyTicketNo));

    //Create array to hold INSERT values
    $values = array();

    //Create the INSERT values
    for($index=0; $index&lt;$min_count; $index++)
    {
    $values[] = "('{$RemedyTicketNo[$index]}','{$PhoneNumber[$index]}','{$Createdate[$index]}',
    '$Category2','$Category3','$Status','$Date','$Severity','$BanType','$XiD')";   
    }

    if (isset($RemedyTicketNo)) 
    {
    $sql="INSERT into tbl_main
    (ars_no,phone_number,create_date,category_1,category_2,status,resolved_date,trouble_type_priority,ban_type,employee_id_name)
    VALUES " . implode (',',$values); 
    $result=mysql_query($sql);

    header("Location: smp_backend.php");
    }
}
</code></pre>
