title: get textarea value, separate by new line, save to database php
body: <p>I have a textarea in my html named <code>add-list</code>. I want to get the value of the textarea per line break and then save it to my database. The problem is, when it saves the input to the database, the second and succeeding entries have a whitespace before the input.</p>
  
  <p>Here is my function for getting the value:</p>
  
  <pre><code>public function add(){
          $checker = false;
          $names = $this-&gt;input-&gt;post('add-list');
  
              if (strpos($names, "\n") == TRUE ) { //newline found
                  $names = nl2br(trim($this-&gt;input-&gt;post('add-list')));
                  $namesArray = explode('&lt;br /&gt;', $names);
  
                  foreach($namesArray as $name) {
                      $checker = false;
                      $checker = $this-&gt;checkDatabase($name); //check if name already exists in database
                      if ($checker) {
                          echo "&lt;script type='text/javascript'&gt;alert('A site in your list already exists. Duplicate sites are not allowed.');&lt;/script&gt;";
                      }
  
                      if (!$checker) {
                          $this-&gt;data_model-&gt;addCommunity($name);
                      }
                  }
  
                  $this-&gt;index();
                  redirect(base_url());
              }
  
              else if (strpos($names, "\n") == FALSE) {
                  $checker = $this-&gt;checkDatabase($names);
                  if ($checker) {
                      echo "&lt;script type='text/javascript'&gt;alert('" . $names . " already exists. Duplicate sites are not allowed.'); window.location.href='".base_url()."'&lt;/script&gt;";
                  }
  
                  if (!$checker) {
                      $this-&gt;data_model-&gt;addCommunity($names);
                      $this-&gt;index();
                      redirect(base_url());
                  }
              }
      }
  </code></pre>
  
  <p>What I get in my database is like this:</p>
  
  <pre><code>firstName
   secondName //there's a whitespace before 's'
  </code></pre>
  
  <p>Help me please!!!</p>