在wordpress / PHP

时间:2018-08-11 15:04:51

标签: php wordpress diacritics iso-8859-1 fputs

我有一个在PHP 7.0.22上运行的wordpress 4.9.8网站。该网站使用UTF-8。我需要将ISO 8859-1中的订单数据输出到我们的供货商的FTP服务器。在用fputs()写入数据之前,我已经用utf8_decode()转换了数据。所有这一切都很好。

但是突然之间-我相信在wordpress更新之后-如果数据包含德语变音符号,则fputs将不再起作用。例如。如果数据中有一个“Ä”(在字符串中编码为0xC4),则fputs不会向文件中写入任何内容,因此不会导出数据。

在我看来,在fput中,系统下方或系统中的某个位置,会检查字符串中的所有字符是否均为有效字符,并且如果包含ISO 8859-1字符,则该功能将中止。

这是我的代码的摘录:

    $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

有人有什么主意吗?wordpress中发生了什么变化?为什么fputs不再使用这些德语字符?我该怎么做才能正确书写?

2 个答案:

答案 0 :(得分:0)

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

打开上部链接会很有帮助。

utf8_decode —将使用UTF-8编码的ISO-8859-1字符的字符串转换为单字节ISO-8859-1

utf8_encode —将ISO-8859-1字符串编码为UTF-8

答案 1 :(得分:-1)

$utf8 = 'ÄÖÜ'; // file must be UTF-8 encoded
$iso88591_1 = utf8_decode($utf8);
$iso88591_2 = iconv('UTF-8', 'ISO-8859-1', $utf8);
$iso88591_2 = mb_convert_encoding($utf8, 'ISO-8859-1', 'UTF-8');

$iso88591 = 'ÄÖÜ'; // file must be ISO-8859-1 encoded
$utf8_1 = utf8_encode($iso88591);
$utf8_2 = iconv('ISO-8859-1', 'UTF-8', $iso88591);
$utf8_2 = mb_convert_encoding($iso88591, 'UTF-8', 'ISO-8859-1');