|
Posted by HaggMan on 06/03/06 18:59
I'm creating a page that:
- accepts user input in whatever language
- saves that input to a file
- reads the file and displays the original input
The following code successfully writes the user input to a file (when I
open the file, it's in the correct font), but I can't get PHP to read
the file and display the correct characters.
HTML --------------- Form
<FORM name=saveform method=post action="wiki.php">
File:
<TEXTAREA name=thetext rows=20 cols=30></TEXTAREA>
</TEXTAREA>
<INPUT type=submit>
<INPUT type=hidden name=action value="save">
</FORM>
PHP --------------- Sticks the data in a file
$message = $_REQUEST['thetext'];
echo $message; // This displays the correct stuff
$filename = "tmp/tmp.txt";
$fr = fopen($filename, "wb+");
// adding header
fwrite($fr, pack("CCC",0xef,0xbb,0xbf));
fputs($fr, $message);
fclose($fr);
PHP --------------- Read the data from the file
$thefile = file($filename);
array_shift($thefile); //To get rid of the BOM
$ret = "";
foreach ($thefile as $i => $line) {
$line = rtrim(utf8_decode($line));
$ret .= $line;
}
echo $ret; // This _doesn't_ display the correct stuff
[Back to original message]
|