读取文件的代码,linux下没事,在win有个乱码字符?

gln gln 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我写了个程序,是往一个文件里追加数据:
$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);
}
}
?>
...全文
评论 5
收藏 已收藏
分享
返回顶部
gln
基础编程 21,889 成员 140,329 内容