views:

64

answers:

2

Hi

Is it possible to pass a variable to 'file_get_contents' in php? Am getting errors and wondered if it was my syntax. Am using 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);

thanks

rifki

+5  A: 

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']);

Maerlyn
+2  A: 

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.

Ronn0