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.
My Answer:
The $escape argument in str_getcsv is used to specify an escape character that can be used to escape the separator character within the input string. In your example, you are using the escape character as "\" and the separator as ".".
When you pass "test\\.a.b" as the input string, the escape character "\" is used to escape the separator ".", so the result is ["test\.", "a", "b"]. If you want the result to be ["test.a", "b"], you can try using a different escape character or removing the escape character altogether.
For example, you can try the following code:
php
str_getcsv("test\\.a.b", ".", "'", "");
This should give you the desired result of ["test.a", "b"].
Rate this post
3 of 5 based on 4714 votesComments