php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45332 Win.Srv'08 + IIS7 + PHP 5.2.6 + MySQL 5
Submitted: 2008-06-23 00:26 UTC Modified: 2008-07-02 11:39 UTC
From: xpower dot ltd at gmail dot com Assigned:
Status: Not a bug Package: *Unicode Issues
PHP Version: 5.2.6 OS: Windows Server 2008
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: xpower dot ltd at gmail dot com
New email:
PHP Version: OS:

 

 [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...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-02 11:39 UTC] jani@php.net
You should be writing the file in binary mode:

$fh = fopen($myFile, 'wb') or die("can't open file");

Notice the 'b' there..
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jan 17 23:01:23 2020 UTC