开发者

Converting ob_get_clean results in PHP

开发者 https://www.devze.com 2023-04-13 07:00 出处:网络
I am working on an existing php site, and it has an export page which spits out data and is saved into text documents. (txt & xtg)

I am working on an existing php site, and it has an export page which spits out data and is saved into text documents. (txt & xtg)

$output = ob_get_clean();

The problem I'm trying to fix is the encoding of the output, apparently the charcters are not displaying correctly. I'm pretty sure the database is in the correct UTF-8 format.

The issues show up like this La Fédération

I tried the following, but it didn't work - the output is still wrong - any ideas ?

$output = mb_convert_encoding($output, "UTF-8");

this is the rest of the relevant cod开发者_开发技巧e

// Ouput file.
// Set DOS line endings for Quark 6
file_put_contents( "/var/www/vhosts/artsdb.net/httpdocs/export/" . $type . "/" . $filename . ".xtg.txt", str_replace( array( "\n", "\r\n\r\n" ), array( "\r\n", "\r\n" ), $output ) );

echo "Exporting " . str_replace( "_", " ", $filename ) . " ($type) complete.\n\n";

Thanks for looking


I am assuming the data displays properly on the site itself and the browser shows your pages are UTF-8.

To troubleshoot this, I would first remove any encoding conversion and try to open the text file in a web browser to eliminate any issues with how you're looking at the file and to confirm it is indeed coming out in UTF-8.

If the browser above shows the content in the text file is not utf-8, try calling utf8_encode on the $output before writing it to file.

0

精彩评论

暂无评论...
验证码 换一张
取 消