Save PHP variables to a text file

后端 未结 7 1592
梦如初夏
梦如初夏 2020-11-29 00:59

I was wondering how to save PHP variables to a txt file and then retrieve them again.

Example:

There is an input box, after submitted the stuff that was writ

7条回答
  •  长情又很酷
    2020-11-29 01:38

    This should do what you want, but without more context I can't tell for sure.

    Writing $text to a file:

    $text = "Anything";
    $var_str = var_export($text, true);
    $var = "";
    file_put_contents('filename.php', $var);
    

    Retrieving it again:

    include 'filename.php';
    echo $text;
    

提交回复
热议问题