Save data to CSV and encode to utf-8 [duplicate] - php

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 3 years ago.
I have a database encoded as utf8mb4. I connect with this database and I set utf8 charset:
$dbHandler = new PDO("mysql:host=$dbHost;dbname=$dbName;charset=utf8mb4", $dbUsername, $dbPassword);
All data is property encoded in DB. I want to fetch data and save it as CSV:
$fp = fopen('data.csv', 'w+');
foreach ($result as $row) {
...
fputcsv($fp, $csvData, ';');
}
But then all the encoding is broken:
groÃ<9f>e,
Zubehör. etc.
I've tried to add BOM (didn't help) and convert array_map("utf8_encode", $csvData); (some characters are displaying correct: große, Zubehör, but some not: Kabelverl?ng, F?r). Any idea?
EDIT:
Hexdump output beginning of file:
00000000: efbb bf70 726f 6475 6374 3b61 7274 6963 ...product;artic
00000010: 6c65 3b73 6b75 3b64 6174 653b 6e61 6d65 le;sku;date;name
00000020: 0a30 3030 3239 3039 3530 3030 3b3b 3b3b .00028151000;;;;
00000030: 2242 7265 616b 6f75 742d 626f 7820 4b70 "Breakout-box Kp
00000040: 6c2e 223b 223c 7374 726f 6e67 3e42 7265 l.";"<strong>Bre
00000050: 616b 6f75 742d 626f 7820 4b70 6c2e 3c2f akout-box Kpl.</
Hexdump output of file with 1 record where we can see the issue (F..r instead of Für). By the way - original string was modified by ucwords and strtolower:
00000000: 3030 3032 3930 3936 3030 333b 3b3b 3b22 00028151000;;;;"
00000010: 4e65 747a 7465 696c 2032 3230 762f 3132 Netzteil 220v/12
00000020: 7620 46e3 9c72 2041 766c 223b 223c 7374 v F..r Avl";"<st
00000030: 726f 6e67 3e4e 6574 7a74 6569 6c20 3232 rong>Netzteil 22
00000040: 3076 2f31 3276 2046 e39c 7220 4176 6c3c 0v/12v F..r Avl<
00000050: 2f73 7472 6f6e 673e 3c62 723e 3c62 723e /strong><br><br>
00000060: 4f45 4d20 4e75 6d6d 6572 3a20 3030 3032 OEM Nummer: 0002
00000070: 3930 3936 3030 3322 3b31 3038 2e34 363b 9096003";108.46;
00000080: 3030 3032 3930 3936 3030 332d 6e65 747a 00028151000-netz
00000090: 7465 696c 2d32 3230 762d 3132 762d 6675 teil-220v-12v-fu
000000a0: 722d 6176 6c3b 4875 7371 7661 726e 613b r-avl;Husqvarna;
000000b0: 4452 4f50 444f 574e 3b59 3b4e 3b68 7474 DROPDOWN;Y;N;htt
000000c0: 7073 3a2f 2f73 7061 7265 7061 7274 7366 ps://sparepartsf
000000d0: 696e 6465 722e 6b74 6d2e 636f 6d2f 5350 inder.fha.com/SP
000000e0: 462f 496d 6167 6573 2f6d 6170 732f 3130 F/Images/maps/10
000000f0: 3030 3032 3932 302e 6769 663b 313b 4154 0002920.gif;1;AT
00000100: 3b57 6964 6765 743b 224b 544d 204f 7269 ;Ponret;"KTM Ori
00000110: 6769 6e61 6c20 4572 7361 747a 7465 696c ginal Ersatzteil
00000120: 6522 3b22 4875 7371 7661 726e 6120 4e65 e";"Husqvarna Ne
00000130: 747a 7465 696c 2032 3230 762f 3132 7620 tzteil 220v/12v
00000140: 46e3 9c72 2041 766c 202d 204f 454d 204e F..r Avl - OEM N
00000150: 756d 6d65 723a 2030 3030 3239 3039 3630 ummer: 000290960
00000160: 3033 223b 3b22 4b61 7566 656e 2053 6965 03";;"Kaufen Sie
00000170: 2048 7573 7176 6172 6e61 204e 6574 7a74 Husqvarna Netzt
00000180: 6569 6c20 3232 3076 2f31 3276 2046 e39c eil 220v/12v F..
00000190: 7220 4176 6c20 6d69 7420 4f45 4d2d 4e75 r Avl mit OEM-Nu
000001a0: 6d6d 6572 2030 3030 3239 3039 3630 3033 mmer 00028151000
000001b0: 2062 6569 2065 696e 656d 2048 7573 7176 bei einem Husqv
000001c0: 6172 6e61 2d56 6572 7472 6167 7368 c3a4 arna-Vertragsh..
000001d0: 6e64 6c65 722e 2057 6972 2068 6162 656e ndler. Wir haben
000001e0: 2065 696e 6520 6772 6fc3 9f65 2041 7573 eine gro..e Aus
000001f0: 7761 686c 2061 6e20 4875 7371 7661 726e wahl an Husqvarn
00000200: 612d 4572 7361 747a 7465 696c 656e 2c20 a-Ersatzteilen,
00000210: 4163 6365 7373 6f72 6965 732c 2043 6c6f Accessories, Clo
00000220: 7468 696e 672c 204d 5820 4265 6b6c 6569 thing, MX Beklei
00000230: 6475 6e67 2075 6e64 205a 7562 6568 c3b6 dung und Zubeh..
00000240: 722e 220a r.".
file data.csv output:
data.csv: Non-ISO extended-ASCII text, with very long lines

The problem was that I was using strtolower and ucfirst. I changed it to
$name = mb_convert_case($name, MB_CASE_LOWER, "UTF-8");
$name = mb_convert_case($name, MB_CASE_TITLE, "UTF-8");
and it works.

Related

phpseclib doesn't show directory content from SFTP when using nlist() function, but it throws a LengthException

I'm using phpseclib3 v3.0.11 in order to interact with an SFTP.
The login works perfectly and I can also change directory without problems, I can also download a file directly and it works.
The only thing that isn't working is the directory listing with nlist() or rawlist(), I need it to cycle on all the files inside the directory in order to download them because I don't know the filenames in advance.
The error Stacktrace is:
LengthException: 2016226605 bytes needed; 6270 bytes available in /app/vendor/phpseclib/phpseclib/phpseclib/Common/Functions/Strings.php:140
Stack trace:
#0 /app/vendor/phpseclib/phpseclib/phpseclib/Net/SFTP.php(1096): phpseclib3\Common\Functions\Strings::unpackSSH2('s', ' 2 ftpadmin ftp...')
#1 /app/vendor/phpseclib/phpseclib/phpseclib/Net/SFTP.php(974): phpseclib3\Net\SFTP->readlist('/users/MPMCINQU...', false)
#2 /app/vendor/phpseclib/phpseclib/phpseclib/Net/SFTP.php(960): phpseclib3\Net\SFTP->nlist_helper('.', false, '')
#3 /app/job.php(57): phpseclib3\Net\SFTP->nlist()
#4 {main}-> NET_SFTP_INIT (0.0001s)
My code is very simple:
$ftp = new SFTP($ftp_server);
$ftp->login($ftp_user_name, $ftp_password);
$ftp->chdir("OUTBOUND")
print_r($ftp->nlist());
This is the output of $ftp->getSFTPLog() taken after the chdir command:
-> NET_SFTP_READDIR (0.0001s)
00000000 00:00:00:03:31:32:32 ....122
<- NET_SFTP_NAME (0.1175s)
00000000 00:00:00:2c:00:00:00:01:2e:00:00:00:36:64:72:77 ...,........6drw
00000010 78:72:2d:78:2d:2d:2d:20:32:20:66:74:70:61:64:6d xr-x--- 2 ftpadm
00000020 69:6e:20:66:74:70:61:64:6d:69:6e:20:20:20:20:20 in ftpadmin
00000030 20:20:20:30:20:4e:6f:76:20:31:36:20:31:31:3a:33 0 Nov 16 11:3
00000040 33:20:2e:00:00:00:3c:00:00:41:e8:61:93:97:0b:61 3 .......A.a...a
00000050 93:97:0b:00:00:00:02:2e:2e:00:00:00:36:64:72:77 ............6drw
00000060 78:72:2d:78:2d:2d:2d:20:32:20:66:74:70:61:64:6d xr-x--- 2 ftpadm
00000070 69:6e:20:66:74:70:61:64:6d:69:6e:20:20:20:20:20 in ftpadmin
00000080 20:20:20:30:20:53:65:70:20:33:30:20:32:30:32:31 0 Sep 30 2021
00000090 20:2e:2e:00:00:00:3c:00:00:41:e8:61:55:ee:8b:61 ........A.aU..a
000000a0 55:ee:8b:00:00:00:20:43:69:6e:71:75:69:6e:61:5f U..... Cinquina_
000000b0 32:30:32:31:31:31:31:30:2d:30:35:30:39:31:38:2d 20211110-050918-
000000c0 34:35:37:2e:63:73:76:00:00:00:55:2d:72:77:78:72 457.csv...U-rwxr
000000d0 2d:78:2d:2d:2d:20:31:20:66:74:70:61:64:6d:69:6e -x--- 1 ftpadmin
000000e0 20:66:74:70:61:64:6d:69:6e:20:20:20:20:20:20:38 ftpadmin 8
000000f0 39:34:20:4e:6f:76:20:31:30:20:31:30:3a:30:39:20 94 Nov 10 10:09
00000100 43:69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31 Cinquina_2021111
00000110 30:2d:30:35:30:39:31:38:2d:34:35:37:2e:63:73:76 0-050918-457.csv
00000120 00:00:00:3d:00:00:00:00:00:00:03:7e:00:00:81:e8 ...=.......~....
00000130 61:8b:9a:4f:61:8b:9a:4f:00:00:00:20:43:69:6e:71 a..Oa..O... Cinq
00000140 75:69:6e:61:5f:32:30:32:31:31:31:31:30:2d:30:35 uina_20211110-05
00000150 31:33:34:31:2d:37:31:36:2e:63:73:76:00:00:00:55 1341-716.csv...U
00000160 2d:72:77:78:72:2d:78:2d:2d:2d:20:31:20:66:74:70 -rwxr-x--- 1 ftp
00000170 61:64:6d:69:6e:20:66:74:70:61:64:6d:69:6e:20:20 admin ftpadmin
00000180 20:20:20:20:35:39:31:20:4e:6f:76:20:31:30:20:31 591 Nov 10 1
00000190 30:3a:31:33:20:43:69:6e:71:75:69:6e:61:5f:32:30 0:13 Cinquina_20
000001a0 32:31:31:31:31:30:2d:30:35:31:33:34:31:2d:37:31 211110-051341-71
000001b0 36:2e:63:73:76:00:00:00:3d:00:00:00:00:00:00:02 6.csv...=.......
000001c0 4f:00:00:81:e8:61:8b:9b:57:61:8b:9b:57:00:00:00 O....a..Wa..W...
000001d0 20:43:69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31 Cinquina_202111
000001e0 31:30:2d:30:35:31:33:34:31:2d:38:36:34:2e:63:73 10-051341-864.cs
000001f0 76:00:00:00:55:2d:72:77:78:72:2d:78:2d:2d:2d:20 v...U-rwxr-x---
00000200 31:20:66:74:70:61:64:6d:69:6e:20:66:74:70:61:64 1 ftpadmin ftpad
00000210 6d:69:6e:20:20:20:20:20:20:35:36:33:20:4e:6f:76 min 563 Nov
00000220 20:31:30:20:31:30:3a:31:33:20:43:69:6e:71:75:69 10 10:13 Cinqui
00000230 6e:61:5f:32:30:32:31:31:31:31:30:2d:30:35:31:33 na_20211110-0513
00000240 34:31:2d:38:36:34:2e:63:73:76:00:00:00:3d:00:00 41-864.csv...=..
00000250 00:00:00:00:02:33:00:00:81:e8:61:8b:9b:57:61:8b .....3....a..Wa.
00000260 9b:57:00:00:00:20:43:69:6e:71:75:69:6e:61:5f:32 .W... Cinquina_2
00000270 30:32:31:31:31:31:30:2d:30:35:31:33:34:32:2d:34 0211110-051342-4
00000280 30:39:2e:63:73:76:00:00:00:55:2d:72:77:78:72:2d 09.csv...U-rwxr-
00000290 78:2d:2d:2d:20:31:20:66:74:70:61:64:6d:69:6e:20 x--- 1 ftpadmin
000002a0 66:74:70:61:64:6d:69:6e:20:20:20:20:20:31:36:34 ftpadmin 164
000002b0 36:20:4e:6f:76:20:31:30:20:31:30:3a:31:33:20:43 6 Nov 10 10:13 C
000002c0 69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31:30 inquina_20211110
000002d0 2d:30:35:31:33:34:32:2d:34:30:39:2e:63:73:76:00 -051342-409.csv.
000002e0 00:00:3d:00:00:00:00:00:00:06:6e:00:00:81:e8:61 ..=.......n....a
000002f0 8b:9b:57:61:8b:9b:58:00:00:00:20:43:69:6e:71:75 ..Wa..X... Cinqu
00000300 69:6e:61:5f:32:30:32:31:31:31:31:30:2d:30:35:31 ina_20211110-051
00000310 33:34:32:2d:34:34:33:2e:63:73:76:00:00:00:55:2d 342-443.csv...U-
00000320 72:77:78:72:2d:78:2d:2d:2d:20:31:20:66:74:70:61 rwxr-x--- 1 ftpa
00000330 64:6d:69:6e:20:66:74:70:61:64:6d:69:6e:20:20:20 dmin ftpadmin
00000340 20:20:31:30:39:39:20:4e:6f:76:20:31:30:20:31:30 1099 Nov 10 10
00000350 3a:31:33:20:43:69:6e:71:75:69:6e:61:5f:32:30:32 :13 Cinquina_202
00000360 31:31:31:31:30:2d:30:35:31:33:34:32:2d:34:34:33 11110-051342-443
00000370 2e:63:73:76:00:00:00:3d:00:00:00:00:00:00:04:4b .csv...=.......K
00000380 00:00:81:e8:61:8b:9b:57:61:8b:9b:58:00:00:00:20 ....a..Wa..X...
00000390 43:69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31 Cinquina_2021111
000003a0 30:2d:30:35:31:33:34:33:2d:30:35:39:2e:63:73:76 0-051343-059.csv
000003b0 00:00:00:55:2d:72:77:78:72:2d:78:2d:2d:2d:20:31 ...U-rwxr-x--- 1
000003c0 20:66:74:70:61:64:6d:69:6e:20:66:74:70:61:64:6d ftpadmin ftpadm
000003d0 69:6e:20:20:20:20:20:31:36:30:31:20:4e:6f:76:20 in 1601 Nov
000003e0 31:30:20:31:30:3a:31:33:20:43:69:6e:71:75:69:6e 10 10:13 Cinquin
000003f0 61:5f:32:30:32:31:31:31:31:30:2d:30:35:31:33:34 a_20211110-05134
00000400 33:2d:30:35:39:2e:63:73:76:00:00:00:3d:00:00:00 3-059.csv...=...
00000410 00:00:00:06:41:00:00:81:e8:61:8b:9b:58:61:8b:9b ....A....a..Xa..
00000420 58:00:00:00:20:43:69:6e:71:75:69:6e:61:5f:32:30 X... Cinquina_20
00000430 32:31:31:31:31:30:2d:30:35:31:33:34:33:2d:34:39 211110-051343-49
00000440 38:2e:63:73:76:00:00:00:55:2d:72:77:78:72:2d:78 8.csv...U-rwxr-x
00000450 2d:2d:2d:20:31:20:66:74:70:61:64:6d:69:6e:20:66 --- 1 ftpadmin f
00000460 74:70:61:64:6d:69:6e:20:20:20:20:20:20:38:31:34 tpadmin 814
00000470 20:4e:6f:76:20:31:30:20:31:30:3a:31:33:20:43:69 Nov 10 10:13 Ci
00000480 6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31:30:2d nquina_20211110-
00000490 30:35:31:33:34:33:2d:34:39:38:2e:63:73:76:00:00 051343-498.csv..
000004a0 00:3d:00:00:00:00:00:00:03:2e:00:00:81:e8:61:8b .=............a.
000004b0 9b:59:61:8b:9b:59:00:00:00:20:43:69:6e:71:75:69 .Ya..Y... Cinqui
000004c0 6e:61:5f:32:30:32:31:31:31:31:32:2d:30:38:35:31 na_20211112-0851
000004d0 32:33:2d:34:32:34:2e:63:73:76:00:00:00:55:2d:72 23-424.csv...U-r
000004e0 77:78:72:2d:78:2d:2d:2d:20:31:20:66:74:70:61:64 wxr-x--- 1 ftpad
000004f0 6d:69:6e:20:66:74:70:61:64:6d:69:6e:20:20:20:20 min ftpadmin
00000500 20:20:35:39:31:20:4e:6f:76:20:31:32:20:31:33:3a 591 Nov 12 13:
00000510 35:31:20:43:69:6e:71:75:69:6e:61:5f:32:30:32:31 51 Cinquina_2021
00000520 31:31:31:32:2d:30:38:35:31:32:33:2d:34:32:34:2e 1112-085123-424.
00000530 63:73:76:00:00:00:3d:00:00:00:00:00:00:02:4f:00 csv...=.......O.
00000540 00:81:e8:61:8e:71:5d:61:8e:71:5d:00:00:00:20:43 ...a.q]a.q]... C
00000550 69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31:32 inquina_20211112
00000560 2d:30:38:35:31:32:33:2d:35:31:39:2e:63:73:76:00 -085123-519.csv.
00000570 00:00:55:2d:72:77:78:72:2d:78:2d:2d:2d:20:31:20 ..U-rwxr-x--- 1
00000580 66:74:70:61:64:6d:69:6e:20:66:74:70:61:64:6d:69 ftpadmin ftpadmi
00000590 6e:20:20:20:20:20:31:36:34:36:20:4e:6f:76:20:31 n 1646 Nov 1
000005a0 32:20:31:33:3a:35:31:20:43:69:6e:71:75:69:6e:61 2 13:51 Cinquina
000005b0 5f:32:30:32:31:31:31:31:32:2d:30:38:35:31:32:33 _20211112-085123
000005c0 2d:35:31:39:2e:63:73:76:00:00:00:3d:00:00:00:00 -519.csv...=....
000005d0 00:00:06:6e:00:00:81:e8:61:8e:71:5d:61:8e:71:5e ...n....a.q]a.q^
000005e0 00:00:00:20:43:69:6e:71:75:69:6e:61:5f:32:30:32 ... Cinquina_202
000005f0 31:31:31:31:32:2d:30:38:35:31:32:33:2d:35:37:31 11112-085123-571
00000600 2e:63:73:76:00:00:00:55:2d:72:77:78:72:2d:78:2d .csv...U-rwxr-x-
00000610 2d:2d:20:31:20:66:74:70:61:64:6d:69:6e:20:66:74 -- 1 ftpadmin ft
00000620 70:61:64:6d:69:6e:20:20:20:20:20:20:38:31:34:20 padmin 814
00000630 4e:6f:76:20:31:32:20:31:33:3a:35:31:20:43:69:6e Nov 12 13:51 Cin
00000640 71:75:69:6e:61:5f:32:30:32:31:31:31:31:32:2d:30 quina_20211112-0
00000650 38:35:31:32:33:2d:35:37:31:2e:63:73:76:00:00:00 85123-571.csv...
00000660 3d:00:00:00:00:00:00:03:2e:00:00:81:e8:61:8e:71 =............a.q
00000670 5e:61:8e:71:5e:00:00:00:20:43:69:6e:71:75:69:6e ^a.q^... Cinquin
00000680 61:5f:32:30:32:31:31:31:31:32:2d:30:38:35:31:32 a_20211112-08512
00000690 33:2d:36:32:34:2e:63:73:76:00:00:00:55:2d:72:77 3-624.csv...U-rw
000006a0 78:72:2d:78:2d:2d:2d:20:31:20:66:74:70:61:64:6d xr-x--- 1 ftpadm
000006b0 69:6e:20:66:74:70:61:64:6d:69:6e:20:20:20:20:20 in ftpadmin
000006c0 20:35:36:33:20:4e:6f:76:20:31:32:20:31:33:3a:35 563 Nov 12 13:5
000006d0 31:20:43:69:6e:71:75:69:6e:61:5f:32:30:32:31:31 1 Cinquina_20211
000006e0 31:31:32:2d:30:38:35:31:32:33:2d:36:32:34:2e:63 112-085123-624.c
000006f0 73:76:00:00:00:3d:00:00:00:00:00:00:02:33:00:00 sv...=.......3..
00000700 81:e8:61:8e:71:5e:61:8e:71:5e:00:00:00:20:43:69 ..a.q^a.q^... Ci
00000710 6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31:32:2d nquina_20211112-
00000720 30:38:35:31:32:34:2d:37:32:38:2e:63:73:76:00:00 085124-728.csv..
00000730 00:55:2d:72:77:78:72:2d:78:2d:2d:2d:20:31:20:66 .U-rwxr-x--- 1 f
00000740 74:70:61:64:6d:69:6e:20:66:74:70:61:64:6d:69:6e tpadmin ftpadmin
00000750 20:20:20:20:20:20:38:39:34:20:4e:6f:76:20:31:32 894 Nov 12
00000760 20:31:33:3a:35:31:20:43:69:6e:71:75:69:6e:61:5f 13:51 Cinquina_
00000770 32:30:32:31:31:31:31:32:2d:30:38:35:31:32:34:2d 20211112-085124-
00000780 37:32:38:2e:63:73:76:00:00:00:3d:00:00:00:00:00 728.csv...=.....
00000790 00:03:7e:00:00:81:e8:61:8e:71:5f:61:8e:71:5f:00 ..~....a.q_a.q_.
000007a0 00:00:20:43:69:6e:71:75:69:6e:61:5f:32:30:32:31 .. Cinquina_2021
000007b0 31:31:31:32:2d:30:38:35:31:32:34:2d:38:30:35:2e 1112-085124-805.
000007c0 63:73:76:00:00:00:55:2d:72:77:78:72:2d:78:2d:2d csv...U-rwxr-x--
000007d0 2d:20:31:20:66:74:70:61:64:6d:69:6e:20:66:74:70 - 1 ftpadmin ftp
000007e0 61:64:6d:69:6e:20:20:20:20:20:31:36:30:31:20:4e admin 1601 N
000007f0 6f:76:20:31:32:20:31:33:3a:35:31:20:43:69:6e:71 ov 12 13:51 Cinq
00000800 75:69:6e:61:5f:32:30:32:31:31:31:31:32:2d:30:38 uina_20211112-08
00000810 35:31:32:34:2d:38:30:35:2e:63:73:76:00:00:00:3d 5124-805.csv...=
00000820 00:00:00:00:00:00:06:41:00:00:81:e8:61:8e:71:5f .......A....a.q_
00000830 61:8e:71:5f:00:00:00:20:43:69:6e:71:75:69:6e:61 a.q_... Cinquina
00000840 5f:32:30:32:31:31:31:31:32:2d:30:38:35:31:32:34 _20211112-085124
00000850 2d:38:35:38:2e:63:73:76:00:00:00:55:2d:72:77:78 -858.csv...U-rwx
00000860 72:2d:78:2d:2d:2d:20:31:20:66:74:70:61:64:6d:69 r-x--- 1 ftpadmi
00000870 6e:20:66:74:70:61:64:6d:69:6e:20:20:20:20:20:31 n ftpadmin 1
00000880 30:39:39:20:4e:6f:76:20:31:32:20:31:33:3a:35:31 099 Nov 12 13:51
00000890 20:43:69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31 Cinquina_202111
000008a0 31:32:2d:30:38:35:31:32:34:2d:38:35:38:2e:63:73 12-085124-858.cs
000008b0 76:00:00:00:3d:00:00:00:00:00:00:04:4b:00:00:81 v...=.......K...
000008c0 e8:61:8e:71:5f:61:8e:71:5f:00:00:00:20:43:69:6e .a.q_a.q_... Cin
000008d0 71:75:69:6e:61:5f:32:30:32:31:31:31:31:35:2d:30 quina_20211115-0
000008e0 39:32:30:32:33:2d:36:38:39:2e:63:73:76:00:00:00 92023-689.csv...
000008f0 55:2d:72:77:78:72:2d:78:2d:2d:2d:20:31:20:66:74 U-rwxr-x--- 1 ft
00000900 70:61:64:6d:69:6e:20:66:74:70:61:64:6d:69:6e:20 padmin ftpadmin
00000910 20:20:20:20:20:38:35:34:20:4e:6f:76:20:31:35:20 854 Nov 15
00000920 31:34:3a:32:30:20:43:69:6e:71:75:69:6e:61:5f:32 14:20 Cinquina_2
00000930 30:32:31:31:31:31:35:2d:30:39:32:30:32:33:2d:36 0211115-092023-6
00000940 38:39:2e:63:73:76:00:00:00:3d:00:00:00:00:00:00 89.csv...=......
00000950 03:56:00:00:81:e8:61:92:6c:aa:61:92:6c:aa:00:00 .V....a.l.a.l...
00000960 00:20:43:69:6e:71:75:69:6e:61:5f:32:30:32:31:31 . Cinquina_20211
00000970 31:31:35:2d:30:39:32:30:32:33:2d:37:36:37:2e:63 115-092023-767.c
00000980 73:76:00:00:00:55:2d:72:77:78:72:2d:78:2d:2d:2d sv...U-rwxr-x---
00000990 20:31:20:66:74:70:61:64:6d:69:6e:20:66:74:70:61 1 ftpadmin ftpa
000009a0 64:6d:69:6e:20:20:20:20:20:31:31:31:31:20:4e:6f dmin 1111 No
000009b0 76:20:31:35:20:31:34:3a:32:30:20:43:69:6e:71:75 v 15 14:20 Cinqu
000009c0 69:6e:61:5f:32:30:32:31:31:31:31:35:2d:30:39:32 ina_20211115-092
000009d0 30:32:33:2d:37:36:37:2e:63:73:76:00:00:00:3d:00 023-767.csv...=.
000009e0 00:00:00:00:00:04:57:00:00:81:e8:61:92:6c:aa:61 ......W....a.l.a
000009f0 92:6c:aa:00:00:00:20:43:69:6e:71:75:69:6e:61:5f .l.... Cinquina_
00000a00 32:30:32:31:31:31:31:35:2d:30:39:32:30:32:33:2d 20211115-092023-
00000a10 38:36:37:2e:63:73:76:00:00:00:55:2d:72:77:78:72 867.csv...U-rwxr
00000a20 2d:78:2d:2d:2d:20:31:20:66:74:70:61:64:6d:69:6e -x--- 1 ftpadmin
00000a30 20:66:74:70:61:64:6d:69:6e:20:20:20:20:20:31:35 ftpadmin 15
00000a40 36:36:20:4e:6f:76:20:31:35:20:31:34:3a:32:30:20 66 Nov 15 14:20
00000a50 43:69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31 Cinquina_2021111
00000a60 35:2d:30:39:32:30:32:33:2d:38:36:37:2e:63:73:76 5-092023-867.csv
00000a70 00:00:00:3d:00:00:00:00:00:00:06:1e:00:00:81:e8 ...=............
00000a80 61:92:6c:aa:61:92:6c:aa:00:00:00:20:43:69:6e:71 a.l.a.l.... Cinq
00000a90 75:69:6e:61:5f:32:30:32:31:31:31:31:35:2d:30:39 uina_20211115-09
00000aa0 32:30:32:33:2d:39:31:32:2e:63:73:76:00:00:00:55 2023-912.csv...U
00000ab0 2d:72:77:78:72:2d:78:2d:2d:2d:20:31:20:66:74:70 -rwxr-x--- 1 ftp
00000ac0 61:64:6d:69:6e:20:66:74:70:61:64:6d:69:6e:20:20 admin ftpadmin
00000ad0 20:20:20:20:38:35:34:20:4e:6f:76:20:31:35:20:31 854 Nov 15 1
00000ae0 34:3a:32:30:20:43:69:6e:71:75:69:6e:61:5f:32:30 4:20 Cinquina_20
00000af0 32:31:31:31:31:35:2d:30:39:32:30:32:33:2d:39:31 211115-092023-91
00000b00 32:2e:63:73:76:00:00:00:3d:00:00:00:00:00:00:03 2.csv...=.......
00000b10 56:00:00:81:e8:61:92:6c:aa:61:92:6c:aa:00:00:00 V....a.l.a.l....
00000b20 20:43:69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31 Cinquina_202111
00000b30 31:35:2d:30:39:32:30:32:33:2d:39:33:36:2e:63:73 15-092023-936.cs
00000b40 76:00:00:00:55:2d:72:77:78:72:2d:78:2d:2d:2d:20 v...U-rwxr-x---
00000b50 31:20:66:74:70:61:64:6d:69:6e:20:66:74:70:61:64 1 ftpadmin ftpad
00000b60 6d:69:6e:20:20:20:20:20:20:37:39:34:20:4e:6f:76 min 864 Nov 16
000010b0 20:31:31:3a:30:37:20:43:69:6e:71:75:69:6e:61:5f 11:07 Cinquina_
000010c0 32:30:32:31:31:31:31:36:2d:30:36:30:37:34:30:2d 20211116-060740-
000010d0 36:30:30:2e:63:73:76:00:00:00:3d:00:00:00:00:00 600.csv...=.....
000010e0 00:03:60:00:00:81:e8:61:93:90:fe:61:93:90:fe:00 ..`....a...a....
000010f0 00:00:20:43:69:6e:71:75:69:6e:61:5f:32:30:32:31 .. Cinquina_2021
00001100 31:31:31:36:2d:30:36:30:37:34:30:2d:36:38:34:2e 1116-060740-684.
00001110 63:73:76:00:00:00:55:2d:72:77:78:72:2d:78:2d:2d csv...U-rwxr-x--
00001120 2d:20:31:20:66:74:70:61:64:6d:69:6e:20:66:74:70 - 1 ftpadmin ftp
00001130 61:64:6d:69:6e:20:20:20:20:20:31:31:32:30:20:4e admin 804 Nov 16
... need to cut the log for body limit ...
000014c0 20:31:36:20:31:31:3a:31:38:20:43:69:6e:71:75:69 16 11:18 Cinqui
000014d0 6e:61:5f:32:30:32:31:31:31:31:36:2d:30:36:31:38 na_20211116-0618
000014e0 30:30:2d:39:36:34:2e:63:73:76:00:00:00:3d:00:00 00-964.csv...=..
000014f0 00:00:00:00:03:1e:00:00:81:e8:61:93:93:6a:61:93 ..........a..ja.
00001500 93:6a:00:00:00:20:43:69:6e:71:75:69:6e:61:5f:32 .j... Cinquina_2
00001510 30:32:31:31:31:31:36:2d:30:36:32:35:30:31:2d:30 0211116-062501-0
00001520 38:34:2e:63:73:76:00:00:00:55:2d:72:77:78:72:2d 84.csv...U-rwxr-
00001530 78:2d:2d:2d:20:31:20:66:74:70:61:64:6d:69:6e:20 x--- 1 ftpadmin
00001540 66:74:70:61:64:6d:69:6e:20:20:20:20:20:20:38:39 ftpadmin 89
00001550 35:20:4e:6f:76:20:31:36:20:31:31:3a:32:35:20:43 5 Nov 16 11:25 C
00001560 69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31:36 inquina_20211116
00001570 2d:30:36:32:35:30:31:2d:30:38:34:2e:63:73:76:00 -062501-084.csv.
00001580 00:00:3d:00:00:00:00:00:00:03:7f:00:00:81:e8:61 ..=............a
00001590 93:95:0e:61:93:95:0e:00:00:00:20:43:69:6e:71:75 ...a...... Cinqu
000015a0 69:6e:61:5f:32:30:32:31:31:31:31:36:2d:30:36:32 ina_20211116-062
000015b0 39:32:35:2d:38:36:30:2e:63:73:76:00:00:00:55:2d 925-860.csv...U-
000015c0 72:77:78:72:2d:78:2d:2d:2d:20:31:20:66:74:70:61 rwxr-x--- 1 ftpa
000015d0 64:6d:69:6e:20:66:74:70:61:64:6d:69:6e:20:20:20 dmin ftpadmin
000015e0 20:20:20:38:39:38:20:4e:6f:76:20:31:36:20:31:31 898 Nov 16 11
000015f0 3a:32:39:20:43:69:6e:71:75:69:6e:61:5f:32:30:32 :29 Cinquina_202
00001600 31:31:31:31:36:2d:30:36:32:39:32:35:2d:38:36:30 11116-062925-860
00001610 2e:63:73:76:00:00:00:3d:00:00:00:00:00:00:03:82 .csv...=........
00001620 00:00:81:e8:61:93:96:17:61:93:96:17:00:00:00:20 ....a...a......
00001630 43:69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31 Cinquina_2021111
00001640 36:2d:30:36:33:33:33:30:2d:31:33:39:2e:63:73:76 6-063330-139.csv
00001650 00:00:00:55:2d:72:77:78:72:2d:78:2d:2d:2d:20:31 ...U-rwxr-x--- 1
00001660 20:66:74:70:61:64:6d:69:6e:20:66:74:70:61:64:6d ftpadmin ftpadm
00001670 69:6e:20:20:20:20:20:20:38:30:31:20:4e:6f:76:20 in 801 Nov
00001680 31:36:20:31:31:3a:33:33:20:43:69:6e:71:75:69:6e 16 11:33 Cinquin
00001690 61:5f:32:30:32:31:31:31:31:36:2d:30:36:33:33:33 a_20211116-06333
000016a0 30:2d:31:33:39:2e:63:73:76:00:00:00:3d:00:00:00 0-139.csv...=...
000016b0 00:00:00:03:21:00:00:81:e8:61:93:97:0b:61:93:97 ....!....a...a..
000016c0 0b:00:00:00:20:43:69:6e:71:75:69:6e:61:5f:32:30 .... Cinquina_20
000016d0 32:31:31:31:31:36:2d:30:36:33:33:33:30:2d:32:32 211116-063330-22
000016e0 37:2e:63:73:76:00:00:00:55:2d:72:77:78:72:2d:78 7.csv...U-rwxr-x
000016f0 2d:2d:2d:20:31:20:66:74:70:61:64:6d:69:6e:20:66 --- 1 ftpadmin f
00001700 74:70:61:64:6d:69:6e:20:20:20:20:20:20:35:33:38 tpadmin 538
00001710 20:4e:6f:76:20:31:36:20:31:31:3a:33:33:20:43:69 Nov 16 11:33 Ci
00001720 6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31:36:2d nquina_20211116-
00001730 30:36:33:33:33:30:2d:32:32:37:2e:63:73:76:00:00 063330-227.csv..
00001740 00:3d:00:00:00:00:00:00:02:1a:00:00:81:e8:61:93 .=............a.
00001750 97:0b:61:93:97:0b:00:00:00:20:43:69:6e:71:75:69 ..a...... Cinqui
00001760 6e:61:5f:32:30:32:31:31:31:31:36:2d:30:36:33:33 na_20211116-0633
00001770 33:30:2d:32:32:38:2e:63:73:76:00:00:00:55:2d:72 30-228.csv...U-r
00001780 77:78:72:2d:78:2d:2d:2d:20:31:20:66:74:70:61:64 wxr-x--- 1 ftpad
00001790 6d:69:6e:20:66:74:70:61:64:6d:69:6e:20:20:20:20 min ftpadmin
000017a0 20:20:35:33:30:20:4e:6f:76:20:31:36:20:31:31:3a 530 Nov 16 11:
000017b0 33:33:20:43:69:6e:71:75:69:6e:61:5f:32:30:32:31 33 Cinquina_2021
000017c0 31:31:31:36:2d:30:36:33:33:33:30:2d:32:32:38:2e 1116-063330-228.
000017d0 63:73:76:00:00:00:3d:00:00:00:00:00:00:02:12:00 csv...=.........
000017e0 00:81:e8:61:93:97:0b:61:93:97:0b:00:00:00:20:43 ...a...a...... C
000017f0 69:6e:71:75:69:6e:61:5f:32:30:32:31:31:31:31:36 inquina_20211116
00001800 2d:30:36:33:33:33:30:2d:33:30:37:2e:63:73:76:00 -063330-307.csv.
00001810 00:00:55:2d:72:77:78:72:2d:78:2d:2d:2d:20:31:20 ..U-rwxr-x--- 1
00001820 66:74:70:61:64:6d:69:6e:20:66:74:70:61:64:6d:69 ftpadmin ftpadmi
00001830 6e:20:20:20:20:20:20:35:34:33:20:4e:6f:76:20:31 n 543 Nov 1
00001840 36:20:31:31:3a:33:33:20:43:69:6e:71:75:69:6e:61 6 11:33 Cinquina
00001850 5f:32:30:32:31:31:31:31:36:2d:30:36:33:33:33:30 _20211116-063330
00001860 2d:33:30:37:2e:63:73:76:00:00:00:3d:00:00:00:00 -307.csv...=....
00001870 00:00:02:1f:00:00:81:e8:61:93:97:0b:61:93:97:0b ........a...a...
00001880 00:00:00:0c:4f:6c:64:54:65:73:74:46:69:6c:65:73 ....OldTestFiles
00001890 00:00:00:41:64:72:77:78:72:2d:78:2d:2d:2d:20:32 ...Adrwxr-x--- 2
000018a0 20:66:74:70:61:64:6d:69:6e:20:66:74:70:61:64:6d ftpadmin ftpadm
000018b0 69:6e:20:20:20:20:20:20:20:20:30:20:4e:6f:76:20 in 0 Nov
000018c0 31:36:20:31:31:3a:32:33:20:4f:6c:64:54:65:73:74 16 11:23 OldTest
000018d0 46:69:6c:65:73:00:00:00:3c:00:00:41:e8:61:93:94 Files......A.a..
000018e0 cb:61:93:94:cb .a...
Could you help me please? I'm using php 7.2
I realy don't understand what's the problem and googling for this error I haven't found nothing useful so far.

Why is str_getcsv() stripping quotation marks within fields?

The str_getcsv() function is designed to work on a line of CSV text, not on a set of lines. I am trying to use it twice, once to split multiple lines of CSV into an array of lines, and then again on each of those. This solution was working for me, and indeed I supplied it as an answer to another question.
However, I now have a problem whereby the line "AC150AC,",service tool,845.71,-2 is returned as AC150AC,,service tool,845.71,-2, with the quotation marks removed, so the comma is now treated as a separator. In debugging that, I found that multi-line values are now also not working, and are now split in the middle despite being enclosed correctly.
How can I debug this?
$ cat csv.php
<?php
$csv = '130,TEST A 1258 (U10 001),28.66,2
"AC150AC,",service tool,845.71,-2
AL7951,SEA LION,47.19,2
T11,"Test multi-
line segments",587.36,4';
$n = str_getcsv($csv, "\n");
$r = str_getcsv($csv, "\r");
print_r($n);
print_r($r);
$ xxd csv.php
00000000: 3c3f 7068 700a 0a24 6373 7620 3d20 2731 <?php..$csv = '1
00000010: 3330 2c54 4553 5420 4120 3132 3538 2028 30,TEST A 1258 (
00000020: 5531 3020 3030 3129 2c32 382e 3636 2c32 U10 001),28.66,2
00000030: 0a22 4143 3135 3041 432c 222c 7365 7276 ."AC150AC,",serv
00000040: 6963 6520 746f 6f6c 2c38 3435 2e37 312c ice tool,845.71,
00000050: 2d32 0a41 4c37 3935 312c 5345 4120 4c49 -2.AL7951,SEA LI
00000060: 4f4e 2c34 372e 3139 2c32 0a54 3131 2c22 ON,47.19,2.T11,"
00000070: 5465 7374 206d 756c 7469 2d0a 6c69 6e65 Test multi-.line
00000080: 2073 6567 6d65 6e74 7322 2c35 3837 2e33 segments",587.3
00000090: 362c 3427 3b0a 0a24 6e20 3d20 7374 725f 6,4';..$n = str_
000000a0: 6765 7463 7376 2824 6373 762c 2022 5c6e getcsv($csv, "\n
000000b0: 2229 3b0a 2472 203d 2073 7472 5f67 6574 ");.$r = str_get
000000c0: 6373 7628 2463 7376 2c20 225c 7222 293b csv($csv, "\r");
000000d0: 0a0a 7072 696e 745f 7228 246e 293b 0a70 ..print_r($n);.p
000000e0: 7269 6e74 5f72 2824 7229 3b0a 0a rint_r($r);..
$ php csv.php
Array
(
[0] => 130,TEST A 1258 (U10 001),28.66,2
[1] => AC150AC,,service tool,845.71,-2
[2] => AL7951,SEA LION,47.19,2
[3] => T11,"Test multi-
[4] => line segments",587.36,4
)
Array
(
[0] => 130,TEST A 1258 (U10 001),28.66,2
"AC150AC,",service tool,845.71,-2
AL7951,SEA LION,47.19,2
T11,"Test multi-
line segments",587.36,4
)
The problem is that you are splitting it by end of line characters(of various types) which you don't know if they are mid line or genuine end of lines.
A fudge is to use fgetcsv() to do the work for you, so you first have to give it a file to work with. This code creates a temporary file, writes the contents to it and then rewinds the file so the read starts from the beginning...
$fh = tmpfile();
fwrite($fh, $csv);
fseek($fh, 0);
while ( $row = fgetcsv($fh)) {
print_r($row);
}
fclose($fh);
What is the result expected ? I'm not sure to understand what you want.
I guess explode() will help you ?
$csv = '130,TEST A 1258 (U10 001),28.66,2
"AC150AC,",service tool,845.71,-2
AL7951,SEA LION,47.19,2
T11,"Test multi-
line segments",587.36,4';
$n = explode("\n", $csv);
var_dump(array_map('str_getcsv', $n));

Extract images from access with php

I'm trying to extract images from an Access database with php.
I can read the data, it gives me an hexadecimal string with a "\0" after every 254 chars so after a
$pic = str_replace("\0", '', $pic);
$pic = hex2bin($pic);
I get this:
00000000: 151c 1c00 0300 0000 0700 0100 1400 1b00 ................
00000010: ffff ffff 496d 6167 656d 0000 0105 0000 ....Imagem......
00000020: 0300 0000 0400 0000 4449 4200 5a17 0000 ........DIB.Z...
00000030: f5e8 ffff ac13 0300 2800 0000 e200 0000 ........(.......
00000040: df00 0000 0100 2000 0300 0000 7813 0300 ...... .....x...
00000050: c40e 0000 c40e 0000 0000 0000 0000 0000 ................
00000060: 0000 ff00 00ff 0000 ff00 0000 c2d6 dbff ................
00000070: c9e0 e2ff c7db e0ff c3da dcff cbe2 e4ff ................
00000080: c3dd ddff bbd5 d5ff bedb d8ff c2e2 ddff ................
00000090: c0e2 dbff bee0 d9ff b7dc d2ff b1d6 ccff ................
000000a0: a9ce c4ff a1c6 bcff 9dc3 b7ff 88af a0ff ................
000000b0: 86ad 9eff 7fa8 99ff 7aa3 94ff 739c 8dff ........z...s...
000000c0: 6e97 88ff 6792 83ff 6590 81ff 5986 76ff n...g...e...Y.v.
000000d0: 5986 76ff 5986 76ff 5885 75ff 5685 75ff Y.v.Y.v.X.u.V.u.
I think this is a bitmap with an OLE header, but I couldn't find what to do next. How can I save these, ideally as jpeg?
Edit: when I save the data to a file, no program I tried can view/identify the image. Also, none of the imagecreatefrom*() worked. I think I need to handle the header somehow.

wget on a picture generated by a function php

I have this exec triggered at some if condition :
exec('( [ ! -e "ha45_temp" ] && touch ha45_temp && wget http://localhost/index.php/Montor/makeApiCameraPrintscreen?id='.$insert_id .' -O ./images/'. $insert_id.' > /dev/null 2>&1 && sleep 30 && rm ha45_temp ) > /dev/null 2>&1 &');
I'm calling makeApiCameraPrintscreen method from my main controller, and direct its output to this path : -O ./images/ with the name of the $insert_id(I hold in that var a unique id to name the pictures)
This is the method:
public function makeApiCameraPrintscreen(){
$imagename = $this->input->get('id', TRUE);
$datasidget = $this->curl->simple_get('somepictureapi');
$datasid = json_decode($datasidget,true);
$data_sid = $datasid['data']['sid'];
$reqUrl = "somepictureapi";
$imageencode = $this->curl->simple_get($reqUrl);
$this->output->set_content_type('jpeg');
$this->output->set_output($imageencode);
}
My problem is that my wget saves a binary octet stream file( that binary is the from the image thou, but it's not in proper extension).
�t?���q��H�*�ӏ��m�}"�Vo�k��c(���䢐T�m첟
This is a example of a line. Now thing is I'm not sure that I will get the pictures in jpeg format (content-type), but I try'ed thou with jpg/png same output.
What I want to do is to save the picture from my wget in a proper format so that I can open it.
PS1. for Mark:
00000000: 0aff d8ff fe00 104c 6176 6335 362e 3630 .......Lavc56.60
00000010: 2e31 3030 00ff db00 4300 080a 0a0b 0a0b .100....C.......
00000020: 0d0d 0d0d 0d0d 100f 1010 1010 1010 1010 ................
00000030: 1010 1012 1212 1515 1512 1212 1010 1212 ................
00000040: 1414 1515 1717 1715 1515 1517 1719 1919 ................
00000050: 1e1e 1c1c 2323 242b 2b33 ffc4 01a2 0000 ....##$++3......
00000060: 0105 0101 0101 0101 0000 0000 0000 0000 ................
00000070: 0102 0304 0506 0708 090a 0b01 0003 0101 ................
00000080: 0101 0101 0101 0100 0000 0000 0001 0203 ................
00000090: 0405 0607 0809 0a0b 1000 0201 0303 0204 ................

cURL font encoding-error

I want to get contents via cURL from this page.
Here is my code:
$url = $_GET["url"];
$url = str_replace(" ", "%20", $url);
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $url);
curl_setopt($curlSession, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true);
$jsonData = curl_exec($curlSession);
curl_close($curlSession);
if (strpos($url, "toomva.com") >= 0) {
$jsonData = str_replace("toomva.com", "http://av.bsquochoai.ga ⇔ ", $jsonData);
}
if (strpos($url, "Toomva -") >= 0){
$jsonData = str_replace("toomva.com", "http://av.bsquochoai.ga ⇔ ", $jsonData);
}
echo($jsonData);
Here you can find a live demo.
My problem is that the returned text is not as I expect. It has a lot of �����:
��1� � �0�0�:�0�0�:�2�4�,�4�0�0� �-�-�>� �0�0�:�0�0�:�3�3�,�1�4�0� �
�M��i� �k�h�i� �a�n�h� �t�r���n�g� �t�h��y� �k�h�u���n� �m��t� �e�m�,�
�t�h�� �g�i�a�n� �n���y� �n�h�� �c�h��t� �t�a�n� �b�i��n� � �
Can you please help me with this?
Here are the first few bytes of the file you're trying to access:
$ curl -s 'http://toomva.com/Data/subtitle/Duncan%20James%20ft.%20Keedie%20-%20I%20Believe%20My%20Heart.Vie_Syned.srt' | xxd | head
0000000: fffe 3100 0d00 0a00 3000 3000 3a00 3000 ..1.....0.0.:.0.
0000010: 3000 3a00 3200 3400 2c00 3400 3000 3000 0.:.2.4.,.4.0.0.
0000020: 2000 2d00 2d00 3e00 2000 3000 3000 3a00 .-.-.>. .0.0.:.
0000030: 3000 3000 3a00 3300 3300 2c00 3100 3400 0.0.:.3.3.,.1.4.
0000040: 3000 0d00 0a00 4d00 d71e 6900 2000 6b00 0.....M...i. .k.
0000050: 6800 6900 2000 6100 6e00 6800 2000 7400 h.i. .a.n.h. .t.
0000060: 7200 f400 6e00 6700 2000 7400 6800 a51e r...n.g. .t.h...
0000070: 7900 2000 6b00 6800 7500 f400 6e00 2000 y. .k.h.u...n. .
0000080: 6d00 b71e 7400 2000 6500 6d00 2c00 2000 m...t. .e.m.,. .
0000090: 7400 6800 bf1e 2000 6700 6900 6100 6e00 t.h... .g.i.a.n.
It starts with 0xff 0xfe, which is the byte order mark for UTF-16 Little Endian. This information should really be provided in the file's HTTP headers, but apparently not in this case.
You can use PHP's mb_convert_encoding() function to change the file's content into whatever character set you're using for your website. For example, this will convert it into utf-8:
$src = file_get_contents('http://toomva.com/Data/subtitle/Duncan%20James%20ft.%20Keedie%20-%20I%20Believe%20My%20Heart.Vie_Syned.srt');
$utf8src = mb_convert_encoding($src,'UTF-8','UTF-16LE');
header('Content-Type: text/plain; charset=utf-8');
die($utf8src);
However, the file doesn't contain JSON data. Here are the first few lines:
1
00:00:24,400 --> 00:00:33,140
Mỗi khi anh trông thấy khuôn mặt em, thế gian này như chợt tan biến
2
00:00:33,140 --> 00:00:42,700
Tất cả đều phơi bày trong một ánh nhìn thoáng qua
use utf8_encode when you echo your jsonDate :
echo(utf8_encode($jsonData));

Categories