Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #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.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 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!||||

  • #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?

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 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!||||

  • #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.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 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:

    jhl84 (09-10-2007)

  • #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_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.

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Use print_r():
    PHP Code:
    $g->pie_values'.$name.''.print_r($value, 1).' ); 

  • Users who have thanked Inigoesdr for this post:

    jhl84 (09-10-2007)

  • #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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •