...

View Full Version : PHP Write Function



jhl84
09-06-2007, 05:48 AM
<?php

$file = "

<?php

// pass in two arrays, one of data, the other data labels

$g->pie_values( $name, $value );

....

?>";

$fp = fopen("textfile_name.php", "w");

fwrite($fp, $file);

fclose($fp);


?>

The output file is:


<?php

// pass in two arrays, one of data, the other data labels
//
( michael, 30 );

...

?>


I want to create/write a php file. The variable $name and $value has values. When I write to the file it will show the values. How do I show ' $g -> '? $g is not showing because it doesn't have any values but I want to write ' $g -> ' to the file in that form. I hope you get what I mean.

Pls advice, thanks

_Aerospace_Eng_
09-06-2007, 06:15 AM
<?php

$file = "

<?php

// pass in two arrays, one of data, the other data labels

".$g->pie_values( $name, $value )."

....

?>";

$fp = fopen("textfile_name.php", "w");

fwrite($fp, $file);

fclose($fp);


?>
Try that, though it might be better to just write to a text file. And then have textfile_name.php already made and just include the text file.

jhl84
09-06-2007, 06:21 AM
hm...it's doesn't show anything. it's expecting some values. i've tried '".$g->pie_values ."' and the output is ' '.

i wan the output $g->pie_values ....maybe it can't b done?

_Aerospace_Eng_
09-06-2007, 06:30 AM
Oh, I was thinking you wanted to print the return of that function. Variables in double quotes get parsed which is why its blank, try this.

$file = '
<?php

// pass in two arrays, one of data, the other data labels

$g->pie_values( $name, $value );

....

?>';

jhl84
09-06-2007, 07:02 AM
if i change it to


$file = ' $g ->pie_values($name, $value); '

i can't get the values for $name and $value.

$name and $value have values. I want to write it in a way so that what is written on the output file will be




$g->pie_values(michael, 300);

_Aerospace_Eng_
09-07-2007, 04:20 AM
Where is $name and $value coming from? Are they variables in the file that actually writes textfile_name.php? If thats the case try this.

$file = '
<?php

// pass in two arrays, one of data, the other data labels

$g->pie_values( '.$name.', '.$value.' );

....

?>';

jhl84
09-10-2007, 01:41 AM
thanks...that kinda solved the problem.

the variable i'm trying to write to the output file is an array.




$name = 'michael';

$value = array();
for( $i=0; $i<5; $i++ )
{
$data[] = rand(5,15);
}

$file = '
<?php

// pass in two arrays, one of data, the other data labels

$g->pie_values( '.$name.', '.$value.' );

....

?>';


the output file i get is



<?php

// pass in two arrays, one of data, the other data labels

$g->pie_values( michael, Array );

....

?>';


now i can successfully show the value for $name but for $value, I get the word Array instead. I'm hoping to get it to show all the values in the array instead of the word Array.

I'm hoping to get something like this

$g->pie_values( michael, Array ( [0] => 10 [1] => 20 [2] => 30 ) );

Inigoesdr
09-10-2007, 05:32 AM
Use print_r():


$g->pie_values( '.$name.', '.print_r($value, 1).' );

jhl84
09-10-2007, 10:41 AM
thanks guys for the input. i got wat i wanted. thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum