How to use fgetcsv where the input is a string and not a resource?
How to convert the string into a resource?
fgetcsv expects a file handle resource
$str = "1981;2992;19191\n392;488;299\n"some\ntext";199;222";
$array = fgetcsv($str);
Can not use str_getcsv because then I have to split the string by \n before str_getcsv.. If some of the fields contains \n then the output will be incorrect
There is str_getcsv function, it can parse CSV string into an array.
Update: if you cannot use str_getcsv function, try to convert string to stream and use it in fgetcsv:
$stream = fopen('php://memory', 'r+');
fwrite($stream, '1981;2992;19191\n392;488;299');
rewind($stream);
$array = fgetcsv($stream);
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