Jump to content

fwrite in chinese>"<


ted_chou12

Recommended Posts

hello, i am trying to fwrite in chinese texts:

$text = iconv("big5","utf-8", $text);
$file = fopen("text1.txt", "w");
$write = fwrite($file, $text);
fclose($file);


$data = file_get_contents("text1.txt");
$data = iconv("utf-8","big5",$data);
echo $data;

but this doesn't give me chinese texts, gives me things like

½Þ½Þ±C~, does anyone know how i can do this?

 

btw, the $text that goes into fwrite() is from a textarea and input box of some sort, not directly by php.

Thanks Ted.

Link to comment
https://forums.phpfreaks.com/topic/118500-fwrite-in-chinese/
Share on other sites

See, this is why PHP should have added good Unicode implementations before PHP 6.  PHP 6 has native types for Unicode and stuff (like you can even typecast to Unicode).  Can you open the file after saving it and see if it's just gibberish or if it's the correct characters?

Link to comment
https://forums.phpfreaks.com/topic/118500-fwrite-in-chinese/#findComment-610052
Share on other sites

I saw this kind of $text = iconv("big5","utf-8", $text); input on some tutorial in chinese, big5 is the charset of traditional chinese i think

 

in head:

<head>
<title>自介修改</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
</head>

 

ps. print_r($_POST) gives me gibberish as well

Link to comment
https://forums.phpfreaks.com/topic/118500-fwrite-in-chinese/#findComment-610065
Share on other sites

here is the page

<?php
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>自介修改</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
</head>
<?php 		if(isset($_POST['submit'])){
		$place = $_POST['place'];
		$msg = $_POST['msg'];
		$intro = $_POST['intro'];

		$place = stripslashes($place);
		$msg = stripslashes($msg);
		$intro = stripslashes($intro);
		$place = htmlentities($place);
		$msg = htmlentities($msg);
		$intro = htmlentities($intro);

		$intro = str_replace("\r\n", ";seDpNL#", $intro);
		$list = array($place, $msg, $intro);
		$comma_separated = implode(";seDp#", $list);
		$comma_separated = iconv("big5","utf-8", $comma_separated);
		$file = fopen("text1.txt", "w");
		$write = fwrite($file, $comma_separated);
		fclose($file);
		//confirm:
		if($write === false)
		{echo "<p><b>更改錯誤</b></p>";}
		else
		{echo "<p><b>正確儲存</b></p>";}}

		//Set values for form post:
		$data = file_get_contents("text1.txt");
		$data = iconv("utf-8","big5",$data);
		print_r($data);
		$data = explode(";seDp#", $data);
		$intro1 = str_replace(";seDpNL#", "\r\n", $data[2]);?>
		<form name="" action="" method="post">
		<p align=center>
		<font size=5 color=orange>更改字界頁面</font><br />
		<br /><br />
		<b>居住地</b><br/>
		<input name="place" value="<?echo $data[0];?>" type="text" size="30" maxlength="40" /><br />
		<b>及時通</b><br />
		<input name="msg" value="<?echo $data[1];?>" type="text" size="30" maxlength="40" /><br />
		<b>自我介紹</b><br />
		<textarea name="<?php echo $textarea;?>" rows="10" cols="50"><?echo $intro1;?></textarea>
		<br />	
		<input class="button" name="submit" type="submit" value="確定" />
		</p>
		</form>

 

sorry for many posts, i can't seem to find the modify button

Link to comment
https://forums.phpfreaks.com/topic/118500-fwrite-in-chinese/#findComment-610147
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.