替代品 [英] fopen alternative

查看:115
本文介绍了替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

所以,我的问题是,fopen的替代品有哪些(函数等).

解决方案

//to write    
file_put_contents('path_and_filename','content');
//to read:
file_get_contents('path_and_filename');

如果要附加到文件:

file_put_contents('path_and_filename' , 'content' , FILE_APPEND );

您还可以锁定文件:

file_put_contents('path_and_filename' , 'content' , LOCK_EX );

看看下面的链接:

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

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

I've got an simple php script, wich creates a file, add some content and closes it again. But my host disabled the fopen function. I was wondering how I could get around this. My host won't help me. This is my code:

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

I was wondering what alternatives there are. I've read many things about using cUrl, but to me that seems more like getting documents from other sites and using that, instead of creating a document (please tell me if this do is possible).

So, my question is, what are the alternatives to fopen (functions, etc).

解决方案

//to write    
file_put_contents('path_and_filename','content');
//to read:
file_get_contents('path_and_filename');

If you want to append to the file:

file_put_contents('path_and_filename' , 'content' , FILE_APPEND );

You can also lock the file:

file_put_contents('path_and_filename' , 'content' , LOCK_EX );

Take a look at the links below:

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

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

这篇关于替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆