ted_chou12 Posted August 6, 2008 Share Posted August 6, 2008 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 More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 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 More sharing options...
ted_chou12 Posted August 6, 2008 Author Share Posted August 6, 2008 Sounds cool, I tried opening the txt file later, its all gibberish :'( Link to comment https://forums.phpfreaks.com/topic/118500-fwrite-in-chinese/#findComment-610054 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 How are you retrieving $text? Also, are you sure it's in the big5 charset to begin with (never heard of that charset, to be honest. I'm a utf-8 kind of guy). Link to comment https://forums.phpfreaks.com/topic/118500-fwrite-in-chinese/#findComment-610058 Share on other sites More sharing options...
effigy Posted August 6, 2008 Share Posted August 6, 2008 What encoding are you using in your meta tag? What are these Chinese ideograms? What does print_r($_POST) give you? Link to comment https://forums.phpfreaks.com/topic/118500-fwrite-in-chinese/#findComment-610063 Share on other sites More sharing options...
ted_chou12 Posted August 6, 2008 Author Share Posted August 6, 2008 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 More sharing options...
effigy Posted August 6, 2008 Share Posted August 6, 2008 Are the following true? 1. Big5 is the encoding on the page where the data is entered/submitted. 2. The user is entering these characters in Big5. What encoding does your browser claim to be using? Link to comment https://forums.phpfreaks.com/topic/118500-fwrite-in-chinese/#findComment-610108 Share on other sites More sharing options...
ted_chou12 Posted August 6, 2008 Author Share Posted August 6, 2008 yes, i checked the meta tags of where the page is entered/submitted, and I was testing the submited text in traditional chinese. Ted Link to comment https://forums.phpfreaks.com/topic/118500-fwrite-in-chinese/#findComment-610135 Share on other sites More sharing options...
ted_chou12 Posted August 6, 2008 Author Share Posted August 6, 2008 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 More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 You can only edit posts for a certain amount of time so that you don't keep editing your code and confusing people. >_< Link to comment https://forums.phpfreaks.com/topic/118500-fwrite-in-chinese/#findComment-610150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.