|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-06-23 00:26 UTC] xpower dot ltd at gmail dot com
Description:
------------
Writing file somehow messed up XML encoding ?
if we disable the part :
$myFile = "file.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh,$sql);
fclose($fh);
then it is O.K. but else the encoding is messed up.
Reproduce code:
---------------
header("Content-type:text/xml");
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "UTF-8");
...
...
$sql = "SELECT id,name,in_egn,phone,mobile,city FROM contragents ".loadRole('')." name!='' and type='".iconv("UTF-8", "UTF-8",$_GET['sort'])."' ";
$sql.= "ORDER BY ".$_GET["orderBy"]." ".$_GET["direction"]."";
$sql.= " LIMIT ".$posStart.",".$count;
$myFile = "file.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh,$sql);
fclose($fh);
$res = mysql_query ($sql);
...
...
print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
if($res)
{
print("<rows total_count='".$totalCount."' pos='".$posStart."'>\n");
for($i=0;$left= mysql_fetch_array($res);$i++)
Expected result:
----------------
expected UTF-8 getting something else ?
Actual result:
--------------
about the iconv("utf-8","utf-8"... Vista localized versions have some encoding problems of it own, so thats a fix for that...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 20:00:01 2025 UTC |
You should be writing the file in binary mode: $fh = fopen($myFile, 'wb') or die("can't open file"); Notice the 'b' there..