Escaping the separator in str_getcsv

103
May 26, 2022, at 02:00 AM

str_getcsv("test\\.a.b", ".", "'", "\\");

I would expect the above to equal ["test.a", "b"], however it equals ["test\", "a", "b"]. Am I misunderstanding the purpose or usage of the $escape argument? I want to escape the separator such that the result is the former array.

Answer 1

You could use the "enclosure" char to enclose a separator char:

var_dump(str_getcsv("'test.a'.b", ".", "'", "\\"));

Output:

array(2) {
  [0]=>
  string(6) "test.a"
  [1]=>
  string(1) "b"
}
Rent Charter Buses Company
READ ALSO
Retrieve results only where ALL keywords match Laravel

Retrieve results only where ALL keywords match Laravel

I am trying to pull users based on their tags where ALL keywords match

60
Getting an PHP enum from dynamic name

Getting an PHP enum from dynamic name

I´m trying to create an php 81 enum from a dynamic name

49
PHP categories showing only one item

PHP categories showing only one item

I'm trying to create a categories list, where user will be able to choose item with certain category, but as soon as I'm opening any of the categories, where "soon = '2'", there is only one item coming upEverything else works

137
PHP can you convert unicode from within a string

PHP can you convert unicode from within a string

I have a php string with the following

98