php mb_convert_encoding function doesn't work from ASCII to latin-1

Gauthier
        //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 ( � )

deceze

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ASCII encoded unicode to SQL statement in PHP with mb_convert_encoding

From Dev

mb_convert_encoding error: Call to undefined function mb_convert_encoding()

From Dev

php-function fsockopen() doesn't work

From Dev

Php function userInfo doesn't work

From Dev

Php function userInfo doesn't work

From Dev

PHP - execute function doesn't work with implode

From Dev

A method to convert ppm to ascii art doesn't work properly

From Dev

Django: Redirect from function doesn't work

From Dev

Calling function from address doesn't work

From Dev

How to convert Latin-1 character to ascii (Python)

From Dev

Is it a good practice to use mb_convert_encoding function

From Dev

Why php function doesn't work inside second <?php ?>

From Dev

Why php function doesn't work inside second <?php ?>

From Dev

Conversion of ASCII code to Character doesn't work

From Dev

@PreAuthorize doesn't work with function which is called from another function

From Dev

@PreAuthorize doesn't work with function which is called from another function

From Dev

A PHP function to convert decimal ASCII to ASCII char

From Dev

A PHP function to convert decimal ASCII to ASCII char

From Dev

3 Pointers in 1 Function - Calculator doesn´t work

From Dev

".toFixed(1);" doesn't work for my each function

From Dev

php class magick function __call doesn't work

From Dev

Static keyword doesn't work inside PHP generator function

From Dev

Facebook PHP SDK - When I put this in a function, it doesn't work

From Dev

HTML/PHP Passing arguments into javascript function with onclick="" doesn't work

From Dev

PHP function preg_replace doesn't work

From Dev

Sphinx PHP API EscapeString() function doesn't work for SphinxQL?

From Dev

my php hashtag identifier function doesn't work

From Dev

!empty PHP function doesn't work for SQL queries

From Dev

Why doesn't this simple PHP preg_match() function work?

Related Related

  1. 1

    ASCII encoded unicode to SQL statement in PHP with mb_convert_encoding

  2. 2

    mb_convert_encoding error: Call to undefined function mb_convert_encoding()

  3. 3

    php-function fsockopen() doesn't work

  4. 4

    Php function userInfo doesn't work

  5. 5

    Php function userInfo doesn't work

  6. 6

    PHP - execute function doesn't work with implode

  7. 7

    A method to convert ppm to ascii art doesn't work properly

  8. 8

    Django: Redirect from function doesn't work

  9. 9

    Calling function from address doesn't work

  10. 10

    How to convert Latin-1 character to ascii (Python)

  11. 11

    Is it a good practice to use mb_convert_encoding function

  12. 12

    Why php function doesn't work inside second <?php ?>

  13. 13

    Why php function doesn't work inside second <?php ?>

  14. 14

    Conversion of ASCII code to Character doesn't work

  15. 15

    @PreAuthorize doesn't work with function which is called from another function

  16. 16

    @PreAuthorize doesn't work with function which is called from another function

  17. 17

    A PHP function to convert decimal ASCII to ASCII char

  18. 18

    A PHP function to convert decimal ASCII to ASCII char

  19. 19

    3 Pointers in 1 Function - Calculator doesn´t work

  20. 20

    ".toFixed(1);" doesn't work for my each function

  21. 21

    php class magick function __call doesn't work

  22. 22

    Static keyword doesn't work inside PHP generator function

  23. 23

    Facebook PHP SDK - When I put this in a function, it doesn't work

  24. 24

    HTML/PHP Passing arguments into javascript function with onclick="" doesn't work

  25. 25

    PHP function preg_replace doesn't work

  26. 26

    Sphinx PHP API EscapeString() function doesn't work for SphinxQL?

  27. 27

    my php hashtag identifier function doesn't work

  28. 28

    !empty PHP function doesn't work for SQL queries

  29. 29

    Why doesn't this simple PHP preg_match() function work?

HotTag

Archive