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.
精彩评论