Read and write php arrays with python
Project description
php_whisperer
"I heard you help people with PHP problems?" "Truth is, I help PHP with people problems."
Read PHP
Convert PHP arrays to Python objects using read_php
from php_whisperer import read_php
read_php('/tmp/a_php_file.php', variable='data')
Result:
{'My Php Array': ['You', 'get', 'the', 'point']}
### Execute Arbitrary PHP
from php_whisperer import execute_php python_list = execute_php([ "@require '/home/me/a_php_file.php'", "$arr = [];", "foreach ($var_from_php_file as $k => $v) {", " if (strlen($k) > 5) $arr[] = $v;", "}", variable="arr" ])
Read many php files:
from php_whisperer import read_many
file1 = open('/tmp/php_file.php')
file2 = open('/tmp/php_file2.php')
file3 = open('/tmp/php_file3.php')
read_many(file1, file2, "$x = File1::doSomethingWith($something_from_file2)", file3, variable='x')
Result:
{'My Php Array': ['You', 'get', 'the', 'point']}
Write PHP
Convert Python lists and dictionaries to PHP using generate_php
from php_whisperer import generate_php
generate_php([1, 2, 3, 4])
Result:
array(1, 2, 3, 4);
Modern syntax also available:
from php_whisperer import generate_php
generate_php([1, 2, 3, 4], modern=True)
Result:
[1, 2, 3, 4];
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
php_whisperer-2.1.0.tar.gz
(5.4 kB
view hashes)
Built Distribution
Close
Hashes for php_whisperer-2.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24d4cbc46f5695a78231e99a2ac4654db0e33cd19ebd42154cd41262bbcd25b2 |
|
MD5 | 4bccd755d047f9a66ffcc8b557b50b83 |
|
BLAKE2b-256 | 433e06abb2616e50c13a85ae5b765185c58a8ea565926fcc1fdd86303a5c6ee7 |