Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-06-2007, 05:48 AM   PM User | #1
jhl84
New Coder

 
Join Date: May 2006
Posts: 59
Thanks: 2
Thanked 0 Times in 0 Posts
jhl84 is an unknown quantity at this point
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..
jhl84 is offline   Reply With Quote
Old 09-06-2007, 06:15 AM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
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!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 09-06-2007, 06:21 AM   PM User | #3
jhl84
New Coder

 
Join Date: May 2006
Posts: 59
Thanks: 2
Thanked 0 Times in 0 Posts
jhl84 is an unknown quantity at this point
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?
jhl84 is offline   Reply With Quote
Old 09-06-2007, 06:30 AM   PM User | #4
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
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!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 09-06-2007, 07:02 AM   PM User | #5
jhl84
New Coder

 
Join Date: May 2006
Posts: 59
Thanks: 2
Thanked 0 Times in 0 Posts
jhl84 is an unknown quantity at this point
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..
jhl84 is offline   Reply With Quote
Old 09-07-2007, 04:20 AM   PM User | #6
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
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!||||
_Aerospace_Eng_ is offline   Reply With Quote
Users who have thanked _Aerospace_Eng_ for this post:
jhl84 (09-10-2007)
Old 09-10-2007, 01:41 AM   PM User | #7
jhl84
New Coder

 
Join Date: May 2006
Posts: 59
Thanks: 2
Thanked 0 Times in 0 Posts
jhl84 is an unknown quantity at this point
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_valuesmichael, 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_valuesmichael, Array ( [0] => 10 [1] => 20 [2] => 30 )  ); 

Last edited by jhl84; 09-10-2007 at 05:25 AM..
jhl84 is offline   Reply With Quote
Old 09-10-2007, 05:32 AM   PM User | #8
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Use print_r():
PHP Code:
$g->pie_values'.$name.''.print_r($value, 1).' ); 
Inigoesdr is offline   Reply With Quote
Users who have thanked Inigoesdr for this post:
jhl84 (09-10-2007)
Old 09-10-2007, 10:41 AM   PM User | #9
jhl84
New Coder

 
Join Date: May 2006
Posts: 59
Thanks: 2
Thanked 0 Times in 0 Posts
jhl84 is an unknown quantity at this point
thanks guys for the input. i got wat i wanted. thanks!

Last edited by jhl84; 09-10-2007 at 11:15 AM..
jhl84 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 PM.


Advertisement
Log in to turn off these ads.