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

Share this post

Link to post
Share on other sites

What exactly do you think will happen there?  You're trying to use an array in a string context, so it is automatically converting the array to a string.  What do you expect it to do there?

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...