开发者

Creating and writing files with php

Is it possible to pass a variable to 'file_get_contents' in php? Am getting errors and wondered if it was my syntax. Am usi开发者_StackOverflow社区ng the code below.

$page=file_get_contents('http://localhost/home/form.php?id={$data['form_id']}');
$fp=fopen('form.html','w+');
fputs($fp,$page);
fclose($fp);


To use this syntax, use " quotes instead of ' ones.

$page=file_get_contents("http://localhost/home/form.php?id={$data['form_id']}");

or

$page=file_get_contents('http://localhost/home/form.php?id='.$data['form_id']);


I prefer to use just one method for writing and reading a file, for example this 2 combination:


Combination one

Writing: file_put_contents

Reading: file_get_contents


Combination two

Writing: fwrite

Reading: fread


In my opinion that's a little more consistent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜