Jump to content

cant write array to php file with fopen/fwrite, please help


BrainPill
 Share

Recommended Posts


I would like to write the values of an array to a php file.
I use fopen/fwrite/fclose to write the php file.
I can define the array like this:
 

Quote

$fruit = array('apples','bananas','grapes');

But I get an array to string conversion error when the file is created. 

 

<?php 

        $pagename = 'testpage2018a';

        $data = 'abcd987654';

        $fruit = array('apples','bananas','grapes');
        $var5 = '$data';
        $var6 = '$fruit';

        $fopenvar = fopen('F:/www/yourdirectory/test/'.$pagename.'.php', 'w');
                $page_cont = " <html>
                 <body><center>
                 
                 
                <?php 

                        $var5  = '" . $data . "';
                        var_dump($var5);
                        
                        $var6  = '" . $fruit . "';
                        
                        var_dump($var6);
                        
                        
                        ?>
                
                </center>
                </body>
                </html>

?>

 

How to solve this and write an array to a php file?

Edited by BrainPill
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...