php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #31314 wrong translation
Submitted: 2004-12-27 18:24 UTC Modified: 2005-01-11 09:34 UTC
From: yury at gorodok dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.0.2 OS: Windows
Private report: No CVE-ID: None
 [2004-12-27 18:24 UTC] yury at gorodok dot net
Description:
------------
The code must translate UTF-8 to windows-1251,
but it truncates output!
May be old compiled in version of libiconv?

examples follow:
 UTF-8:
  http://yury.gorodok.net/temp/test_.html
 result:
  http://yury.gorodok.net/temp/test_1.html

(the content is not essential, I suppose)

Reproduce code:
---------------
 $fstr=fread($f, $flen);
 $ffstr=iconv( "windows-1251", "UTF-8",$fstr);
  echo fwrite($ff,$ffstr, strlen($ffstr))."\n";



Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-27 19:40 UTC] tony2001@php.net
You have mbstring.func_overload turned On, thus strlen() returns number of characters, not bytes.
Turn it off or just don't use third parameter of fwrite().
 [2004-12-28 16:17 UTC] yury at gorodok dot net
Just not using third parameter in fwrite() _doesn't_help_ a bit! All lines with mbstring were (and are) commented out; I cann't see it in my phpinfo()-- so, I cann't say what value mbstring.func_overload has.
 Here is the code, that doesn't work now:

 $f=fopen($fns, "rb");
 $ff=fopen($fnts, "wb");
 $flen=filesize($fns);
 $fstr=fread($f, $flen);
  echo $flen."\n";
 $ffstr=iconv("UTF-8","windows-1251",$fstr);
  echo strlen($ffstr)."\n";
  echo fwrite($ff,$ffstr/*,strlen($ffstr)*/)."\n";
  fclose($ff);
  fclose($f);

Also, for some other files (that translated good), there was no problem with length.
 [2004-12-28 22:07 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.


 [2004-12-29 14:46 UTC] yury at gorodok dot net
Here is the full script:
(the files on which I've experienced the bug, I've pointed earlier)

<?php //	UTF->WIN
  if ( count($argv)< 2)
   {
    echo "\n2 arguments needed!\n";
    exit;
   }
 $fns=$argv[1];
 $fnts=$argv[2];

 $f=fopen($fns, "rb");
 $ff=fopen($fnts, "wb");
 $flen=filesize($fns);
 $fstr=fread($f, $flen);
  echo $flen."\n";
 $ffstr=iconv("UTF-8","windows-1251",$fstr);
  echo strlen($ffstr)."\n";
  echo fwrite($ff,$ffstr/*,strlen($ffstr)*/)."\n";
  fclose($ff);
  fclose($f);
?>
 [2005-01-10 21:48 UTC] tony2001@php.net
iconv() stops on illegal character. That's not PHP problem, it's usual behaviour of libiconv.
 [2005-01-11 08:46 UTC] derick@php.net
Add //ignore to the target charset, like:
"windows-1251//ignore" and it will just skip the character. IMO this should be put more clearly into the documentation.
 [2005-01-11 09:34 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

//ignore is already mentioned in the docs. I've only added: "Otherwise, str is cut from the first illegal character."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Aug 16 02:01:29 2024 UTC