I have a file that has the Mime-type: text/csv.
I want to iterate through it and make a bunch of string-manipulation.
I have a billion columns and rows. But a simple example:
Foo Bar Grød
------------------
1 2 3
4 5 6
If I just print the values out, straight away, without having done anything, then Laravel prints this (for the headers):
My code:
foreach( $headers as $entry ){
dump( $entry );
}
Output
Foo
Bar
b"Grød"
Now that third line is the problem. It's a binary-string
But I want 'what's inside the b" and ". So I want an output like this:
Foo
Bar
Grød
If I just add utf8_decode, like this:
foreach( $headers as $entry ){
dump( utf8_decode( $entry ) );
}
Foo
Bar
Gr?d
?!
How do I get the actual values from all rows that contains the danish æ, ø and å letters? It's a part of the standard UTF-8-encoding, so it should be rocket science.
Addition1
If I write: dd( $request['csv_file'] ), then it outputs this:
-test: false
-originalName: "FILENAME.csv"
-mimeType: "text/csv"
-error: 0
#hashName: null
path: "/private/var/folders/hl/r1syq9ys4z30lw08b6g8hhnh0000gn/T"
filename: "phpzYwY9I"
basename: "phpzYwY9I"
pathname: "/private/var/folders/hl/r1syq9ys4z30lw08b6g8hhnh0000gn/T/phpzYwY9I"
extension: ""
realPath: "/private/var/folders/hl/r1syq9ys4z30lw08b6g8hhnh0000gn/T/phpzYwY9I"
aTime: 2019-02-20 15:31:10
mTime: 2019-02-20 15:31:10
cTime: 2019-02-20 15:31:10
inode: 12891860254
size: 2282762
perms: 0100600
owner: 501
group: 20
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
I don't know if it's any help to anyone.
And if I (in the terminal) write file -I FILENAME.csv then it outputs: FILENAME.csv: application/octet-stream; charset=binary
b""is only a convention of thatdumputility. There's no difference as far as PHP is concerned, PHP doesn't have anything called "binary strings". There's nothing really at all you need to do. If you want to figure out what the actual encoding of the string is, usebin2hexto look at its actual byte representation.dump( .... )and reload the page (in the browser).in_arraydoesn't find it, that means the encoding of the string in your PHP file (i.e., the encoding of the PHP file), and the encoding of the strings in the array are different.