A spinoff of PHP in Python
Project description
Python PPHP: Hypertext Preprocessor.
PPHP
This is a spinoff of PHP (PHP: Hypertext Preprocessor) that uses Python instead of the PHP language.
How to use it:
To host the server, simply run python -m PPHPServer
To execute Python code inside a file, use:
<?pphp #code here (line breaks permitted) ?>
and output will be recorded in the same way as PHP - through stdout.
Example:
<p>Request method: <?pphp echo(_SERVER['REQUEST_METHOD']) ?></p>
Some special globals:
echo(text) - this is equivalent to sys.stdout.write(text)
__script__ - this is the entire script currently being executed
__db__ - this is the server’s database, more documentation below
_GET - this is the GET data as a dictionary
_POST - this is the POST data as a dictionary
_REQUEST - this is a combination of _GET and _POST
_SERVER - this is the equivalent of PHP’s $_SERVER, with some exceptions described below.
In _SERVER, the keys REQUEST_TIME, HTTP_ACCEPT, HTTP_ACCEPT_CHARSET, HTTP_HOST, HTTP_REFERER, HTTPS, REMOTE_HOST, SERVER_ADMIN, SERVER_SIGNATURE, SCRIPT_NAME, and SCRIPT_URI are all not available; and the key GATEWAY_INTERFACE returns the version of the cgi module, not the gateway interface.
Data for a server can be stored using the global __db__. This is simply a dictionary - you can store and retrieve values as such. Data in __db__ is stored as JSON in the file __DATABASE__, in the current working directory. Changes to __db__ will only show up in __DATABASE__ after all scripts have finished running.
Thanks to:
banana439monkey for help in thinking of the name.
StackOverflow for help with the many problems I experienced.
Python (duh) for having such awesome batteries included.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pphp-2.0.0a4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc47d50e15ae4c230264f5ee10a52a5a55d247fb5ac3a8b6cd770110e8b58693 |
|
MD5 | c1aeefa35182dff285c7492e080e7171 |
|
BLAKE2b-256 | 2da53543498edb6e61e9d53d344b6d024d24d242d0421f0f0a07d3e1712009d0 |