//reencoding string from UTF-8 to Latin1
echo mb_detect_encoding($out);
$out = mb_convert_encoding($out, mb_detect_encoding($out),"ISO-8859-1");
echo mb_detect_encoding($out);
die;
The result printed on my page is :
ASCIIASCII
I already checked the possible encoding supported (http://php.net/manual/fr/mbstring.supported-encodings.php) Latin-1 is knew as ISO-8859-1. But nothing changes...
---[EDIT]---
this is what I get when I print $out before the mb_detect_encoding(); My string is correct. Maybe it could be a php.ini configuration wich mess it up? I am not able to change it ...
EDI_DC40 0000000000027262 2 SALESORDER_CREATEFROMDAT201 SALESORDER_CREATEFROMDAT2 330SOL 96A ORDERSTDX4 LS SERVEURDPL SAPP48 LS SERVEURDPL 1 E2SALESORDER_CREATEFROMDAT2 X E2BPSDHD1000 00000000000272621 YPR 4803 330 0230 20151002 20151002Z300 7134012207 71 20151002 20151002 E2BPSDITM000 00000000000272622 1 L7820100 9 E2BPSDITM000 00000000000272623 2 L7820400 6 E2BPSDITM000 00000000000272624 3 L9188000 5 E2BPPARNR000 00000000000272625 AG0000510001 E2BPPARNR000 00000000000272626 WE0000510001 E2BPPARNR000 00000000000272627 LQ0000030590 E2BPPARNR000 00000000000272628 ZQ0000990238 E2BPSCHDL000 00000000000272629 1 9 E2BPSCHDL000 000000000002726210 2 6 E2BPSCHDL000 000000000002726211 3 5 E2BPSDTEXT000 000000000002726212 FR E2BPPAREX000 000000000002726213 BAPE_VBAK LX2 E2BPPAREX000 000000000002726214 BAPE_VBAKX X
ASCII ASCII
[EDIT2]
I still have some issues to get my file encoded in ISO-8851-1. I juste added $out = utf8_decode($out);
before to generate my file :
$strFileWrite = fopen($filePath, "w");
$strWritableFile = fwrite($strFileWrite, $out);
fclose($strFileWrite);
When I add "Ô" at the end of the $out variable, the file is recognized in latin-1, and the ô is well printed. When I add it in the middle of my file, the document is recognized in utf8 and the character "ô" is poorly printed ( � )
As written here:
Strings have no actual associated encoding, they're merely byte arrays.
mb_detect_encoding
doesn't tell you what encoding the string has, it merely tries to detect it. That means it takes a few guesses (your second argument) and tells you the first that is valid.
If your original string is ASCII, it's already also valid Latin-1, UTF-8 and a whole bunch of other encodings for that matter, which are all supersets of ASCII. Converting it won't actually change anything. mb_detect_encoding
preferably detects it as ASCII, since it's the first valid match, and it's as valid an answer as virtually anything else.
If you require Latin-1 and you want to confirm that your string is valid in the Latin-1 encoding, use mb_check_encoding($str, 'ISO-8859-1')
.
Maybe start reading here to understand more: What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments