lets say we want to make a python config reader from php.
config.php
$arr = array(
'a config',
'b config',
'c config => 'with values'
)
$arr2 = array(
'a config',
'b config',
'c config => 'with values'
)
readconfig.py
f = open('config.php', 'r')
// somehow get the array then turns it into pythons arr1 and arr2
print arr1
# arr1 = {'a config', 'b config', 'c config': 'with values'}
print arr2
# arr2 = {'a config', 'b config', 'c config': 'with values'}
is this possible in python ?
from subprocess import check_output
import json
config = check_output(['php', '-r', 'echo json_encode(include "config.php");'])
config = json.loads(config)
where config.php
returns an array:
return [
'param1' => 'value1',
'param2' => 'value2',
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With