将PHP变量保存到文本文件 [英] Save PHP variables to a text file

查看:685
本文介绍了将PHP变量保存到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将PHP变量保存到txt文件中,然后
再次获取它们。

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

示例:

有一个输入框,在提交了以
编写的东西后,输入框将被保存到一个文本文件中。后来结果需要
作为变量被带回来。所以让我们说变量是$ text I
需要保存到一个文本文件,并能够再次找回

There is an input box, after submitted the stuff that was written in the input box will be saved to a text file. Later on the results need to be brought back as a variable. So lets say the variable is $text I need that to be saved to a text file and be able to retrieve it back again.

推荐答案

这应该做你想要的,但没有更多的上下文我无法确定。

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

将$文本写入文件:

$text = "Anything";
$var_str = var_export($text, true);
$var = "<?php\n\n\$text = $var_str;\n\n?>";
file_put_contents('filename.php', $var);

再次检索:

include 'filename.php';
echo $text;

这篇关于将PHP变量保存到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆