0

I use a form which purpose is to generate a customized .csv file. Among other things, the user can specify the end of line character.

To do so, he simply enters it in a text area. I have a problem with the backslashed characters, and in particular "\n".

If I don't check the string, the "\n" entered by the user isn't evaluated. It is added to the .csv file as a string, and the outputed CSV has only one line with all the values...: value1\nvalue2\n instead of :

value 1
value 2
...

So far, I've found a way to deal with it, making the following test :

if ($var == '\n') {
$var = "\n";
}

Is there a more elegant way to solve this problem ?

Fafanellu
  • 424
  • 4
  • 20
  • 2
    Add checkboxes/radio with possible options. – u_mulder Jul 28 '15 at 15:52
  • why are you giving this as an option? "\n" is a very standard way of ending datalines in csv files – iam-decoder Jul 28 '15 at 15:53
  • the problem will be the same, what I want to know is how to force the evaluation of the string as an end-of-file character – Fafanellu Jul 28 '15 at 15:53
  • I could let this "\n" option forced by default, but now I'm curious of what happened. I found a way to avoid the error, I just want to know why it happens in this case... – Fafanellu Jul 28 '15 at 15:55
  • give this a quick read and then look at how you read the csv file and how you read the input from the user: [PHP Strings](http://php.net/manual/en/language.types.string.php) – iam-decoder Jul 28 '15 at 15:56
  • I currently use `if (isset($_GET['var'])) { $var = $_GET['var']; }` I also tried with double quotes – Fafanellu Jul 28 '15 at 16:00

0 Answers0