使用php将文本写入站点上的文件

时间:2015-02-03 05:50:28

标签: php

我是PHP的新手,我想将文本写入.html文件我想在像http://anyurl.com/path/page.html这样的网址上写入数据 代码如下。

$file = "http://anyurl.com/path/page.html";
$text = "Hello world";
file_put_contents($file, $text);

但它无法成功运作 我做错了什么?

1 个答案:

答案 0 :(得分:2)

试试这个..它可以正常工作:)

<?php

$myfile = fopen("newfile.html", "w") or die("Unable to open file!");

$txt = "John Doe\n";

fwrite($myfile, $txt);

$txt = "Jane Doe\n";

fwrite($myfile, $txt);

fclose($myfile);
?>