Page 1 of 1

iconv (conversion between different Charset e.g.UTF8->Big

Posted: Fri Jun 06, 2003 12:02 pm
by rebyphp
I have asked not too long ago about conversions between Big5 to UTF8. I got the answer. You need to have iconv php support in Apache server and the iconv libiconv installed.

Here is the code I come up:

Code: Select all

<?php

	$file = fopen("utf8text.txt","r");

		while (!feof($file))
   		&#123;
      		$content = fgets($file, 1000000);
      		$out = iconv ("utf-8","big5", $content);
      		echo $out;     	
   		&#125;
	
	fclose($file);
	
	$ofile = fopen ("out.txt", "w+");
	fwrite ($ofile, $out);
	fclose($ofile);

?>
I believe the code can used to exchange same language with different encoding (e.g. Big5 <-> BG, ECU <-> Shift JIS). I never try. Correct me if wrong.

I have problems regarding this code. When a file is long, output text in text file will be truncated either in the beginning or at the end. However, the displayed text will be okay. I am confused.

What is the problem with this one?

Code: Select all

$ofile = fopen ("out.txt", "w+");
	fwrite ($ofile, $out);
	fclose($ofile);
Thanks