I have the below mentioned code (actually, configuration) written in a file (config.php) and i want to get the content written in config.php in another file (check.php)
Codes written in config.php:
<?php
$CONFIG = array (
'id' => 'asd5646asdas',
'dbtype' => 'mysql',
'version' => '5.0.12',
);
Code written in check.php to get the content is:
$config_file_path = $_SERVER['DOCUMENT_ROOT'] . 'config.php';
$config = file_get_contents($config_file_path);
Using the above code i am getting the output as a string and i wanted to convert it into an array. To do so, i have tried the below code.
$config = substr($config, 24, -5); // to remove the php starting tag and other un-neccesary things
$config = str_replace("'","",$config);
$config_array = explode("=>", $config);
Using the above code, i am getting an output like:
Array
(
[0] => id
[1] => asd5646asdas,
dbtype
[2] => mysql,
version
[3] => 5.0.12
)
which is incorrect.
Is there any way to convert it into an array. I have tried serialize() as well as mentioned in accessing array from another page in php , but did not succeed.
Any help on this will be appreciated.