0

I have a wordpress 4.9.8 website running on PHP 7.0.22. The website uses UTF-8. I need to output the order data in ISO 8859-1 to the FTP server of our fulfillment provider. I have converted the data with utf8_decode() before writing them with fputs(). All this was working fine.

But suddenly - I believe after a wordpress update - fputs is not working any longer if the data contains German umlaut characters. E.g. if there is an 'Ä' in the data, which is encoded as 0xC4 in the string, then fputs doesn't write anything to the file so that the data are not exported.

It looks to me that in fputs or somewhere below or in the system there is a check if all characters in the string are valid characters and the function is aborted if a ISO 8859-1 character is included.

This is an excerpt from my code:

    $stream  = fopen( 'php://output', 'w' );
    fputs( $stream, $header );  // working well
    $mytext = $this->get_row_csv( $row, $headers ); // get the order data
    $mytext1 = utf8_decode($mytext); // convert to ISO 8859-1
    fputs( $stream, $mytext1 ); // OK with no umlaut, fails if umlaut is included

Does anybody have an idea, what has been changed in wordpress or why fputs has stopped working with these German characters and what I can do to write correctly?

1 Answers1

0

encoding - Convert utf8-characters to iso-88591 and back in PHP

Open upper link it's would be helpful.

utf8_decode — Converts a string with ISO-8859-1 characters encoded with UTF-8 to single-byte ISO-8859-1

utf8_encode — Encodes an ISO-8859-1 string to UTF-8

joki3
  • 11
  • 6
  • Thanks for your answer. However, the problem is not in the conversion of the string, but in writing it to a file. After successfully converting to is-8859-1 the string cannot be written. fputs doesn't write anything, if the string contains a non utf8 character (like 0xC4 for "Ä"). – Manfred Aug 13 '18 at 10:07
  • plz try fopen with binary mode fopen('file' 'wb'); $stream = fopen( 'php://output', 'wb' ); – joki3 Aug 15 '18 at 09:23
  • Unfortunately that doesn't solve the problem. Same effect as before. If a non UTF8 character is included in the string, the whole string is not written. – Manfred Aug 16 '18 at 10:18