I want to make a CSV file importer on my website. I want the user to choose the delimiter.
The problem is when the form submits, the delimiter field is stored as '\t', for example, so when I'm parsing the file, I search for the string '\t' instead of a real TAB. It does the same thing with every special characters like \r, \n, etc...
I want to know the way or the function to use to convert these characters to their true representation without using an array like:
The tab character (unicode U+0009) is typically converted to spaces (unicode U+0020) by the white space processing rules and then collapsed so that only one space in a row is displayed in the browser.
Adding Tab Space in HTML Unlike with HTML space, there is no particular HTML tab character you could use. You could technically use the 	 entity as the tab is character 9 in the ASCII.
You should probably decide what special chars will you allow and create a function like this one:
function translate_quoted($string) {
$search = array("\\t", "\\n", "\\r");
$replace = array( "\t", "\n", "\r");
return str_replace($search, $replace, $string);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With