//读取文件内容
if(!function_exists('Readf'))
{
function Readf($file)
{
if(file_exists($file) && is_readable($file))
{
if(function_exists('file_get_contents'))
{
$str = file_get_contents($file);
}
else
{
$str = '';
$fp = fopen($file, 'r');
while(!feof($fp))
{
$str .= fgets($fp, 1024);
}
fclose($fp);
}
return $str;
}
else
{
return FALSE;
}
}
}
//写入文件内容
if(!function_exists('Writef'))
{
function Writef($file,$str,$mode='w')
{
if(file_exists($file) && is_writable($file))
{
$fp = fopen($file, $mode);
flock($fp, 3);
fwrite($fp, $str);
fclose($fp);
return TRUE;
}
else if(!file_exists($file))
{
$fp = fopen($file, $mode);
flock($fp, 3);
fwrite($fp, $str);
fclose($fp);
}
else
{
return FALSE;
}
}
}
php常用自建函数学习(7):读取文件内容和写入文件内容
关注
打赏