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

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 related to php forms explode delimiter nl2br

The answer is


You could try a different approach like read the file line by line instead of dealing with all this nl2br / explode stuff.

$fh = fopen("employees.txt", "r"); if ($fh) {     while (($line = fgets($fh)) !== false) {         $line = trim($line);         echo "<option value='".$line."'>".$line."</option>";     } } else {     // error opening the file, do something } 

Also maybe just doing a trim (remove whitespace from beginning/end of string) is your issue?

And maybe people are just misunderstanding what you mean by "submitting results to a spreadsheet" -- are you doing this with code? or a copy/paste from an HTML page into a spreadsheet? Maybe you can explain that in more detail. The delimiter for which you split the lines of the file shouldn't be displaying in the output anyway unless you have unexpected output for some other reason.


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

Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to forms

How do I hide the PHP explode delimiter from submitted form results? React - clearing an input value after form submit How to prevent page from reloading after form submit - JQuery Input type number "only numeric value" validation Redirecting to a page after submitting form in HTML Clearing input in vuejs form Cleanest way to reset forms Reactjs - Form input validation No value accessor for form control TypeScript-'s Angular Framework Error - "There is no directive with exportAs set to ngForm"

Examples related to explode

How do I hide the PHP explode delimiter from submitted form results? Mysql where id is in array Convert array values from string to int? Php multiple delimiters in explode PHP: Split string into array, like explode with no delimiter Explode string by one or more spaces or tabs

Examples related to delimiter

How do I hide the PHP explode delimiter from submitted form results? How do I use a delimiter with Scanner.useDelimiter in Java? Split function in oracle to comma separated values with automatic sequence Split String by delimiter position using oracle SQL SQL split values to multiple rows How to use delimiter for csv in python Hive load CSV with commas in quoted fields How to escape indicator characters (i.e. : or - ) in YAML Delimiters in MySQL Split comma separated column data into additional columns

Examples related to nl2br

How do I hide the PHP explode delimiter from submitted form results? How to remove line breaks (no characters!) from the string? line breaks in a textarea How can I replace newline or \r\n with <br/>?