fopen替代方案

Jan*_*men 4 php fopen

我有一个简单的PHP脚本,创建一个文件,添加一些内容并再次关闭它.但我的主机禁用了fopen功能.我想知道如何解决这个问题.我的主人不会帮助我.这是我的代码:

$f = fopen($id."/adres.xml", "w");
fwrite($f, 'some content');
fclose($f);
Run Code Online (Sandbox Code Playgroud)

我想知道有什么替代品.我已经阅读了许多关于使用cUrl的内容,但对我而言,这似乎更像是从其他网站获取文档并使用它,而不是创建文档(请告诉我这是否可行).

所以,我的问题是,fopen(函数等)的替代方法是什么.

小智 11

//to write    
file_put_contents('path_and_filename','content');
//to read:
file_get_contents('path_and_filename');
Run Code Online (Sandbox Code Playgroud)

如果要附加到文件:

file_put_contents('path_and_filename' , 'content' , FILE_APPEND );
Run Code Online (Sandbox Code Playgroud)

你也可以锁定文件:

file_put_contents('path_and_filename' , 'content' , LOCK_EX );
Run Code Online (Sandbox Code Playgroud)

看看下面的链接:

http://php.net/manual/en/function.file-put-contents.php

http://php.net/manual/en/function.file-get-contents.php