How do I hide the PHP explode delimiter from submitted form results?

0

I have created a form which utilizes a .txt file to pull the names of the EMPLOYEES from and breaks them up in the SELECT form option using the PHP explode function.

<select name="FakeName" id="Fake-ID" aria-required="true" required>  <option value=""></option>   <?php    $options=nl2br(file_get_contents("employees.txt"));    $options=explode("<br />",$options);     for($i=0;$i<count($options);$i++)    {     echo "<option value='".$options[$i]."'>".$options[$i]."</option>";    }  ?> </select> 

The .txt file appears as such:

Name 1 Name 2 Name 3 ETC 

Now this works in the form on the site and properly breaks it up and all looks fine. However, when the results are submitted into a SPREADSHEET (in this case a GOOGLE SPREADSHEET) the output includes the "break" and thus it goes into the spreadsheet in a format similar to:

Row 1: Name 1 Row 2:        Name 2 Row 3:        Name 3 Row 4:        ETC 

I am trying to figure out how to change the code or something so that the delimiter itself does not submit as part of the results. NOTE: Using any delimiter submits. I have tried "\" or ";" and it submits with results.

This question is tagged with php forms explode delimiter nl2br

~ Asked on 2013-12-31 22:19:00

The Best Answer is


0

Instead of adding the line breaks with nl2br() and then removing the line breaks with explode(), try using the line break character '\r' or '\n' or '\r\n'.

<?php     $options= file_get_contents("employees.txt");     $options=explode("\n",$options);        // try \r as well.      foreach ($options as $singleOption){         echo "<option value='".$singleOption."'>".$singleOption."</option>";     }   ?> 

This could also fix the issue if the problem was due to Google Spreadsheets reading the line breaks.

~ Answered on 2013-12-31 22:35:26


0

<select name="FakeName" id="Fake-ID" aria-required="true" required>  <?php $options=nl2br(file_get_contents("employees.txt")); $options=explode("<br />",$options);  foreach ($options as $item_array) { echo "<option value='".$item_array"'>".$item_array"</option>";  } ?> </select> 

Most Viewed Questions: