读取文件的代码,linux下没事,在win有个乱码字符?
gln 2004-02-17 09:14:16 我写了个程序,是往一个文件里追加数据:
$handle = fopen($this->file_name,"a");
fwrite($handle,$string);
fclose($handle);
然后当我使用fread读出来的时候有一个乱码字符,可是在linux就没有问题.这是怎么回事啊.
代码如下:
<?php
class file_opt
{
var $file_name;
//default constructor
function file_opt()
{
//default value,please your information replace it
$this->file_name = 'C:\\apache\\htdocs\\chatroom\\chatroom.txt';
}
function get_file_name()
{
return $this->file_name;
}
function set_file_name($name)
{
$this->file_name = $name;
}
//Get a string contain content of the file
function read_file_to_string()
{
$handle = fopen($this->file_name,"r");
$content = fread($handle, filesize($this->file_name));
fclose($handle);
return $content;
}
//append come contents to file
function append_to_file($string)
{
$handle = fopen($this->file_name,"a");
fwrite($handle,$string);
fclose($handle);
}
}
?>