Enjoy an ad free experience by logging in. Not a member yet?
Register .
09-06-2007, 05:48 AM
PM User |
#1
New Coder
Join Date: May 2006
Posts: 59
Thanks: 2
Thanked 0 Times in 0 Posts
PHP Write Function
Code:
<?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:
Code:
<?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
Last edited by jhl84; 09-06-2007 at 05:52 AM ..
09-06-2007, 06:15 AM
PM User |
#2
Supreme Master coder!
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
PHP Code:
<?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.
__________________
|||| If you are getting paid to do a job, don't ask for help on it! ||||
09-06-2007, 06:21 AM
PM User |
#3
New Coder
Join Date: May 2006
Posts: 59
Thanks: 2
Thanked 0 Times in 0 Posts
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?
09-06-2007, 06:30 AM
PM User |
#4
Supreme Master coder!
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
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.
PHP Code:
$file = '<?php // pass in two arrays, one of data, the other data labels $g -> pie_values ( $name , $value ); .... ?> ';
__________________
|||| If you are getting paid to do a job, don't ask for help on it! ||||
09-06-2007, 07:02 AM
PM User |
#5
New Coder
Join Date: May 2006
Posts: 59
Thanks: 2
Thanked 0 Times in 0 Posts
if i change it to
Code:
$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
Code:
$g->pie_values(michael, 300);
Last edited by jhl84; 09-06-2007 at 07:40 AM ..
09-07-2007, 04:20 AM
PM User |
#6
Supreme Master coder!
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
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.
PHP Code:
$file = '<?php // pass in two arrays, one of data, the other data labels $g -> pie_values ( '.$name.' , '.$value.' ); .... ?> ';
__________________
|||| If you are getting paid to do a job, don't ask for help on it! ||||
Users who have thanked _Aerospace_Eng_ for this post:
09-10-2007, 01:41 AM
PM User |
#7
New Coder
Join Date: May 2006
Posts: 59
Thanks: 2
Thanked 0 Times in 0 Posts
thanks...that kinda solved the problem.
the variable i'm trying to write to the output file is an array.
PHP Code:
$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 Code:
<?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
PHP Code:
$g -> pie_values ( michael , Array ( [ 0 ] => 10 [ 1 ] => 20 [ 2 ] => 30 ) );
Last edited by jhl84; 09-10-2007 at 05:25 AM ..
09-10-2007, 05:32 AM
PM User |
#8
Super Moderator
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Use print_r():
PHP Code:
$g -> pie_values ( '.$name.' , '.print_r($value, 1).' );
Users who have thanked Inigoesdr for this post:
09-10-2007, 10:41 AM
PM User |
#9
New Coder
Join Date: May 2006
Posts: 59
Thanks: 2
Thanked 0 Times in 0 Posts
thanks guys for the input. i got wat i wanted. thanks!
Last edited by jhl84; 09-10-2007 at 11:15 AM ..
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 04:19 PM .
Advertisement
Log in to turn off these ads.