php - Storing an escape sequence in a variable for use later -


this might seem trivial, it's curiosity that's been bugging me somewhat.

i have front-end page user uploads csv file. can select delimiter, file, , on, , have server process request. if user selects "tab" option, example, '\t' stored delimiter in variable, can retrieve model later.

the problem arises when try use value, as-is;

$csv->setdelimiter($this->csv_delimiter); 

because it's not being treated escape sequence, league\csv (the library using) throw exception, stating delimiter must single character.

i can overcome doing so;

if($this->csv_delimiter == '\t'){     $csv->setdelimiter("\t"); } else{     $csv->setdelimiter($this->csv_delimiter); } 

however me seems cumbersome , bit of code smell. tried enclosing variable in double-quotes within setdelimiter method, doesn't work either. there way force variable work escape sequences? or perhaps should working more literal representations, such character codes/hex codes?

edit:

i think see problem, now;

<?= $form->field($model, 'csv_delimiter')->dropdownlist([',' => 'comma',                                                          ';' => "semicolon",                                                          '\t' => 'tab']); ?> 

i'm storing literal string, rather escape sequence. reason it's required field. when used double-quotations, wouldn't work. realise it's because jquery treating tab blank value, , not accepting it, why switched single-quotes.

i'll either have remove validation or apply callback on validator (likely), both should resolve issue.

have tried enclose variable this: $csv->setdelimiter("{$this->csv_delimiter}"); ?

i used sample of code check it:

$obj = json_decode(json_encode(array("a" => "\t")));  var_dump("{$obj->a}"); // output: string(1) "   " 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -