php 中 var-export 函数的反义词是什么?

发布于 2025-01-06 11:05:48 字数 672 浏览 0 评论 0原文

我通过 "var_export($schools,true 将变量导出到文本区域)”以便用户可以编辑它。然后我想用所做的更改来“更新”变量。通过 POST 方法接收更新。

我有一些文本,我想成为变量。我怎样才能做到这一点?

我现在所做的是在 .php 文件中手动编辑变量。我想为用户提供一个网络界面来实现同样的目的。不会有安全问题,因为这只是严格的内部工具。

变量样本

$schools = array(

    "PHCS"=> array(
        "full_name"=> "Pacific Hills Christian School",
        "version"=> "4.0.2b",
        "etc"=> "etc"
      ),

    "WAC"=> array(
        "full_name"=> "Wollondilly Anglican College",
        "version"=> "4.0.1",
        "etc"=> "etc"
      ),
  );

I export a variable to a textarea via "var_export($schools,true)" so user can edit it. Then I want to 'update' the variable with the changes made. The updates is received via POST method.

I have some text that I want to become a variable. How can I do that?

What I do right now is that I edit the variable manually in .php file. I want to give an web interface to users do to the same. There won't be no security issues as this will be strictly inhouse tool only.

Sample of the variable

$schools = array(

    "PHCS"=> array(
        "full_name"=> "Pacific Hills Christian School",
        "version"=> "4.0.2b",
        "etc"=> "etc"
      ),

    "WAC"=> array(
        "full_name"=> "Wollondilly Anglican College",
        "version"=> "4.0.1",
        "etc"=> "etc"
      ),
  );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素手挽清风 2025-01-13 11:05:48

您将考虑使用 eval()由于安全风险,其使用颇具争议。

我建议您使用 serialize() 和 < a href="http://php.net/manual/en/function.serialize.php" rel="nofollow">unserialize(),或者更好的是 JSON 函数代替。

JSON 编码/解码将是向用户显示的最佳选择,因为它具有相当的可读性。

You would be looking at using eval() which use of is pretty controversial due to security risks.

I would suggest you use serialize() and unserialize(), or even better, the JSON functions instead.

The JSON encode/decode would be the best option for displaying to the user as it's fairly readable.

思念满溢 2025-01-13 11:05:48

按照 php.net 上的建议,如果您打算更改对象,则应该使用序列化和反序列化:

$var = serialize(array('hello'));
// string(22) "a:1:{i:0;s:5:"hello";}"
var_dump( unserialize($var) );

Following the advice on php.net, if you plan to change the object you should use serialize and unserialize:

$var = serialize(array('hello'));
// string(22) "a:1:{i:0;s:5:"hello";}"
var_dump( unserialize($var) );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文