Jump to content

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


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:


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

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



        $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>

                        $var5  = '" . $data . "';
                        $var6  = '" . $fruit . "';



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

  • Create New...