[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

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

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.

Questions with php tag:

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? Target class controller does not exist - Laravel 8 Message: Trying to access array offset on value of type null Array and string offset access syntax with curly braces is deprecated Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error How to fix "set SameSite cookie to none" warning? The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac What does double question mark (??) operator mean in PHP Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client php mysqli_connect: authentication method unknown to the client [caching_sha2_password] Converting a POSTMAN request to Curl Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required Issue in installing php7.2-mcrypt Xampp localhost/dashboard How can I run specific migration in laravel How to change PHP version used by composer Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory Artisan migrate could not find driver phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO) Ajax LARAVEL 419 POST error Laravel 5.5 ajax call 419 (unknown status) laravel 5.5 The page has expired due to inactivity. Please refresh and try again "The page has expired due to inactivity" - Laravel 5.5 How to increment a letter N times per iteration and store in an array? Can't install laravel installer via composer Only on Firefox "Loading failed for the <script> with source" Is there way to use two PHP versions in XAMPP? How to prevent page from reloading after form submit - JQuery laravel Eloquent ORM delete() method No Application Encryption Key Has Been Specified General error: 1364 Field 'user_id' doesn't have a default value How to logout and redirect to login page using Laravel 5.4? How to uninstall an older PHP version from centOS7 How to Install Font Awesome in Laravel Mix PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers Laravel - htmlspecialchars() expects parameter 1 to be string, object given How to downgrade php from 7.1.1 to 5.6 in xampp 7.1.1?

Questions with forms tag:

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" Angular 2: Can't bind to 'ngModel' since it isn't a known property of 'input' In Angular, how to add Validator to FormControl after control is created? How to disable input conditionally in vue.js Mask for an Input to allow phone numbers? angular2 submit form by pressing enter without submit button How to convert Base64 String to javascript file object like as from file input form? Manually Set Value for FormBuilder Control Angular 2: Get Values of Multiple Checked Checkboxes Can I use an HTML input type "date" to collect only a year? How to make 'submit' button disabled? Angular2 - Radio Button Binding How to redirect back to form with input - Laravel 5 Adding form action in html in laravel Multiple radio button groups in one form Setting onSubmit in React.js Laravel form html with PUT method for PUT routes How To Pass GET Parameters To Laravel From With GET Method ? Show loading gif after clicking form submit using jQuery Postman Chrome: What is the difference between form-data, x-www-form-urlencoded and raw How to submit an HTML form without redirection Laravel - Form Input - Multiple select for a one to many relationship Angularjs how to upload multipart form data and a file? How to hide form code from view code/inspect element browser? jQuery AJAX form data serialize using PHP How to make <label> and <input> appear on the same line on an HTML form? Form Submission without page refresh Fetching data from MySQL database using PHP, Displaying it in a form for editing Adding asterisk to required fields in Bootstrap 3 What's the difference between "Request Payload" vs "Form Data" as seen in Chrome dev tools Network tab How to get HTML 5 input type="date" working in Firefox and/or IE 10 Laravel use same form for create and edit Send value of submit button when form gets posted Angular is automatically adding 'ng-invalid' class on 'required' fields Submit form after calling e.preventDefault() How to send a JSON object using html form data Comparing two input values in a form validation with AngularJS Jquery function BEFORE form submission Clear text input on click with AngularJS Access Form - Syntax error (missing operator) in query expression How to Call a JS function using OnClick event

Questions with explode tag:

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

Questions with delimiter tag:

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 How to specify more spaces for the delimiter using cut? String delimiter in string.split method Split string with multiple delimiters in Python How to make the 'cut' command treat same sequental delimiters as one? C# List<string> to string with delimiter Split a string into an array of strings based on a delimiter Eclipse and Windows newlines How do I escape a single quote in SQL Server? Can you use a trailing comma in a JSON object?

Questions with nl2br tag:

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