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
如何从另一个php页面读取数组_Php_Arrays_File - Fatal编程技术网

如何从另一个php页面读取数组

如何从另一个php页面读取数组,php,arrays,file,Php,Arrays,File,实际上,我有下面提到的代码,配置写在config.php文件中,我想在另一个文件check.php中得到config.php中写的内容 用config.php编写的代码: 使用上面的代码,我得到的输出是一个字符串,我想把它转换成一个数组。为此,我尝试了以下代码 $config = substr($config, 24, -5); // to remove the php starting tag and other un-neccesary things $config = str_repla

实际上,我有下面提到的代码,配置写在config.php文件中,我想在另一个文件check.php中得到config.php中写的内容

用config.php编写的代码:

使用上面的代码,我得到的输出是一个字符串,我想把它转换成一个数组。为此,我尝试了以下代码

$config = substr($config, 24, -5); // to remove the php starting tag and other un-neccesary things

$config = str_replace("'","",$config);
$config_array = explode("=>", $config);
使用上述代码,我得到如下输出:

Array
(
    [0] =>   id 
    [1] =>  asd5646asdas,
  dbtype 
    [2] =>  mysql,
  version 
    [3] =>  5.0.12
)
这是不正确的

有没有办法将其转换为数组。我尝试了序列化以及中提到的,但没有成功

在此方面的任何帮助都将不胜感激

简单

include_file "config.php";
简单的

include_file "config.php";

你怎么可能没有读到指令的内容

$config = file_get_contents($config_file_path);
必须是:

require_once $config_file_path;
// now you can use variables, classes and function from this file
var_dump($config);

如果您遵循链接,请阅读一次有关包含和包含的内容。作为一名PHP开发人员,您必须了解这一点。这是基本的

你怎么可能没有读到有关该指令的内容

$config = file_get_contents($config_file_path);
必须是:

require_once $config_file_path;
// now you can use variables, classes and function from this file
var_dump($config);

如果您遵循链接,请阅读一次有关包含和包含的内容。作为一名PHP开发人员,您必须了解这一点。这是基本的

如果你这么做的话,我对你的方法感到非常困惑:

include(config.php);
然后,$CONFIG变量将在其他页面上可用

print_r($CONFIG);

请看一下。

如果您只是这样做,我对您的方法感到非常困惑:

include(config.php);
然后,$CONFIG变量将在其他页面上可用

print_r($CONFIG);

查看。

如果您使用codeigniter无需包含配置文件,您可以使用$this访问,但是如果您使用的是普通php,您需要使用include或require或include_once或require_once

如果您使用codeigniter无需包含配置文件,您可以使用$this访问,但是如果您使用的是普通php,您需要使用include或require或include\u once或require\u once

您不需要文件获取内容:

您不需要文件获取内容:


使用include或require包含并执行文件。区别在于当文件不存在时会发生什么。inlcude将抛出警告,要求出现错误。 要确保第一次加载和执行文件时也可以使用include\u一次,请使用一次 如果您不知何故无法包含该文件,有什么原因需要查看eval以从字符串执行php代码。但由于安全原因,这一点都不推荐

require_once('config.php');
include_once('config.php');
require('config.php');
include('config.php');

使用include或require包含并执行文件。区别在于当文件不存在时会发生什么。inlcude将抛出警告,要求出现错误。 要确保第一次加载和执行文件时也可以使用include\u一次,请使用一次 如果您不知何故无法包含该文件,有什么原因需要查看eval以从字符串执行php代码。但由于安全原因,这一点都不推荐

require_once('config.php');
include_once('config.php');
require('config.php');
include('config.php');

您可以包括该文件。如果要解析数组,可以选中此项。答案中有a和a,您可以包括该文件。如果要解析数组,可以选中此项。答案中有a和a是的。。。我真的忘了这个方法。哦,是的。。。我真的忘记了这种方法。是的,我使用的是codeigniter,但是config.php文件位于框架之外。我会试试你的建议。是的,我正在使用codeigniter,但是config.php文件位于框架之外。我会试试你的建议。