Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP5将实际数组写入文件_Php_Arrays_File - Fatal编程技术网

PHP5将实际数组写入文件

PHP5将实际数组写入文件,php,arrays,file,Php,Arrays,File,有一个包含在所有页面中的文件,内容如下 <?php site['subTitle'] = "Welcome to the Site"; ?> 在一个页面上,我试图通过表单文本字段将“欢迎访问网站”更改为“无论什么”,然后保存包含的文件,以便获得: <?php site['subtitle'] = "Whatever"; ?> 目前我无法写出这个,任何人都知道怎么写。您尝试过json和文件内容($

有一个包含在所有页面中的文件,内容如下

    <?php

        site['subTitle'] = "Welcome to the Site";
    ?>

在一个页面上,我试图通过表单文本字段将“欢迎访问网站”更改为“无论什么”,然后保存包含的文件,以便获得:

    <?php
        site['subtitle'] = "Whatever";
    ?>


目前我无法写出这个,任何人都知道怎么写。您尝试过json和文件内容($filename,print\r($site,true)),但结果输出不符合我的要求。

这就是您的意思吗

$contents = "<?php\n\n\$site = array();\n";

foreach ($strings as $key => $value) {
    $contents.= '$site[\''.$key.'\'] = \''.$value.'\';'."\n";
}

file_put_contents($path_to_file, $contents);

$contents=“
site['subTitle']
这不是你真正的代码,对吧?
site
目前被视为一个常量。你在设计CMS吗?如果你不得不问这样的问题,你似乎应该安装一个已经设计好的。