php将一个txt文件用base64编码并保存

下面是代码,要解码,只需要将stream_filter_append($fp, 'convert.base64-encode',STREAM_FILTER_WRITE);中的encode改为“decode”即可!

if(is_readable('./a.txt')||is_writable('./a.txt')){
$arr=file('./a.txt');
$newArr=array();
foreach ($arr as $value)
{ $value=trim($value);
if($value!=='')
$newArr[]=$value;
}
echo $newArr[count($newArr)-1];
print_r($newArr);
$fp=fopen('./a.txt','w+');//echo $content;
stream_filter_append($fp, 'convert.base64-encode',STREAM_FILTER_WRITE);
foreach ($newArr as $value)
fwrite($fp,$value."\r\n");
fclose($fp);
}

你可能感兴趣的:(PHP,base64,编码,filter,append)