- Компилятор с python на php
- Key differences between Python and PHP
- Saved searches
- Use saved searches to filter your results more quickly
- License
- jneuendorf/python_to_php
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- License
- dan-da/py2php
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- bullsoft/PHPython
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
Компилятор с python на php
This free online converter lets you convert code from Python to PHP in a click of a button. To use this converter, take the following steps —
- Type or paste your Python code in the input box.
- Click the convert button.
- The resulting PHP code from the conversion will be displayed in the output box.
Key differences between Python and PHP
Characteristic | Python | PHP |
---|---|---|
Syntax | Python has a simple and easy-to-learn syntax that emphasizes readability and reduces the cost of program maintenance. It uses indentation to create blocks, instead of curly braces. | PHP syntax is similar to C and Perl. It uses curly braces to define blocks of code and semicolons to terminate statements. |
Paradigm | Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming. | PHP is primarily a procedural programming language, but it also supports object-oriented programming. |
Typing | Python is dynamically typed, which means that variable types are determined at runtime. | PHP is also dynamically typed. |
Performance | Python is generally slower than compiled languages like C and Java, but it is faster than interpreted languages like PHP. | PHP is slower than compiled languages like C and Java, but it is faster than some other interpreted languages. |
Libraries and frameworks | Python has a large number of libraries and frameworks for various purposes, including web development, scientific computing, and data analysis. Some popular libraries and frameworks include Django, Flask, NumPy, and Pandas. | PHP also has a large number of libraries and frameworks, including Laravel, Symfony, and CodeIgniter, which are popular for web development. |
Community and support | Python has a large and active community of developers who contribute to open-source projects and provide support through forums and online communities. | PHP also has a large and active community of developers who contribute to open-source projects and provide support through forums and online communities. |
Learning curve | Python has a relatively easy learning curve, especially for beginners who are new to programming. Its syntax is simple and easy to read, and there are many resources available for learning Python. | PHP has a moderate learning curve, but it can be more difficult for beginners who are new to programming. Its syntax is similar to C and Perl, which can be more challenging for some learners. |
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A python to PHP transpiler
License
jneuendorf/python_to_php
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
A python to PHP transpiler.
Still in an early stage. Just found dan-da/py2php which might be a helpful source.
- Compile any python code (though probably with some restrictions/conventions)
- classes
- class methods
- instance methods
- multiple inheritance
- keyword and positional arguments
- scoping like in python (e.g. support nonlocal )
- decorators
- emulate the protocol for rich comparison, attribute lookup etc.
Restrictions (things that probably won’t compile correctly)
- nested classes (http://stackoverflow.com/a/1765716)
- virtual subclasses (abstract base classes)
- __metaclass__ attribute on classes to define what meta class to use. Should use metaclass=MC in the class definition.
About
A python to PHP transpiler
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
py2php is a utility that will auto-translate python code into PHP code.
License
dan-da/py2php
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
py2php is a utility that will auto-translate python code into PHP code.
It is intended as a porting aid only. You will still need to review the generated PHP and make tweaks. But it does handle a lot of the grunt work and common cases.
py2php is a heavily modified copy of pyjs.py from the pyjamas project. pyjs.py was written to translate python to javascript. py2php changes the output semantics from JS to php.
Here’s a simple python program to generate a sequence of fibonacci numbers.
def gen_fib(count): i = 1 if count == 0: fib = [] elif count == 1: fib = [1] elif count == 2: fib = [1,1] elif count > 2: fib = [1,1] while i (count - 1): fib.append(fib[i] + fib[i-1]) i += 1 return fib print gen_fib(10)
and here is the autogenerated PHP.
require_once('py2phplib.php'); function gen_fib($count) < $i = 1; if (($count == 0)) < $fib = array(); > else if (($count == 1)) < $fib = array(1); > else if (($count == 2)) < $fib = array(1, 1); > else if (($count > 2)) < $fib = array(1, 1); while (($i < ($count - 1))) < $fib[] = ($fib[$i] + $fib[($i - 1)]); $i += 1; > > return $fib; > pyjslib_printFunc(gen_fib(10));
Both produce the exact same output:
$ python fibonacci.py [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
$ php fibonacci.py.php [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
The file py2phplib.php contains some PHP functions that emulate python keywords such as print, range, etc. py2php automatically renames these keywords to call the emulated functions instead.
Look in the tests directory for more examples.
translate_python_to_php is a wrapper script for py2php. Run it in any directory without arguments and it will attempt to translate all the .py files into .php files.
Run it with one or more arguments, and it will attempt to translate the files in the argument list.
Python uses + for string concatenation and PHP uses dot (.).
Because python variables are dynamically typed, it is not possible for py2php to know if a given variable represents a string or a number.
py2php attempts to deal with this by:
- If either side of the expression is a string constant, then use dot operator.
- If either side of the expression is a variable that contains «str» or «buf» in the name, then use dot operator.
- For all other cases, use plus operator.
This means that if your string variable names do not contain «str» or «buf» then you will need to manually change all related occurrences of «+» to «.».
When porting python code, I have been manually creating a subdirectory named _autotranslated, into which I move all the original .py files. I then run translate_python_to_php which creates all the translated .php files. I then copy (not move!) those generated files back into the parent directory for review and tweaking, to finish the port.
This way, the _autotranslated directory contains only original .py files and the autogenerated .php files. This should make things easier in the future when the upstream python project releases a new version. Then we will simply copy the new .py files into a new tmp directory, re-run the autotranslater, and then we have a nice PHP PHP diff we can use as a porting aid. Once the port is complete, the tmp directory files should replace the contents of _autotranslated directory.
About
py2php is a utility that will auto-translate python code into PHP code.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
PHPython: An extension to eval python3 codes in PHP
bullsoft/PHPython
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
An extension to eval python codes in PHP
- pybind11 V2.1.1
- PHP-CPP-LEGACY V1.5.7 / PHP-CPP V2.x
- PHP 5 / PHP 7
- Python 3
- C++ 11
Variables defined in Python
$code = a = [1, 2, 3] EOD; $python = new Python(); $python->eval($code); var_export($python->extract("a"));
. you can use extract method in php to get that python variable, codes above output:
$a = ["a" => "b", "c" => "d"]; $code = print(a) EOD; $python = new Python(); $python->assign("a", $a); $python->eval($code);
. you can use assign method in php to let python know that php variable, codes above output:
Functions defined in Python
$a = ["a" => "b", "c" => "d"]; $code = def dofunc(arg1, arg2): print("Python Output") print(arg1) print(arg2) return > after = "abcd" EOD; $python = new Python(); $python->eval($code); $python->assign("tmp", $a); var_dump("PHP Here. ", $python->dofunc($a, "py::tmp"));
. you can call functions defined in Python as-is-a $python->method() , codes above output:
string(11) "PHP Here. " array(1) < 'Python' =>array(2) < 'a' =>array(2) < 'a' =>string(1) "b" 'c' => string(1) "d" > 'b' => array(2) < 'a' =>string(1) "b" 'c' => string(1) "d" > > >
Here, We can also use these ways to call functions defined in Python:
var_dump("PHP Here. ", $python->call("dofunc", [$a, "py::tmp"])); var_dump("PHP Here. ", $python->call("dofunc(after, tmp)"));
Python Output // $a in php // tmp in python which assigned by php string(11) "PHP Here. " array(1) < 'Python' =>array(2) < 'a' =>array(2) < 'a' =>string(1) "b" 'c' => string(1) "d" > 'b' => array(2) < 'a' =>string(1) "b" 'c' => string(1) "d" > > > Python Output abcd // after in python // tmp in python which assigned by php string(11) "PHP Here. " array(1) < 'Python' =>array(2) < 'a' =>string(4) "abcd" 'b' => array(2) < 'a' =>string(1) "b" 'c' => string(1) "d" > > >
$code = tmp = print("Python begin") print(dofunc(tmp)) print("Python end") EOD; $python = new Python(); $python->def("dofunc", function($param) < echo __function__ . " in PHP: Get params from Python :" . PHP_EOL; echo var_export($param, true) . PHP_EOL; return [ "php" => $param ]; >); $python->eval($code);
. you can call php funciton in python as-is-a real python function, codes above output:
Python begin in PHP: Get params from Python : array ( 0 => array ( 'a' => 'b', 'c' => 'd', ), ) ]> Python end
if you like, you can also call that function using the php way, like this:
var_dump($python->dofunc("py::tmp", "phpString"));
in PHP: Get params from Python : array ( 0 => array ( 'a' => 'b', 'c' => 'd', ), 1 => 'phpString', ) array(1) < 'php' =>array(2) < [0] =>array(2) < 'a' =>string(1) "b" 'c' => string(1) "d" > [1] => string(9) "phpString" > >
About
PHPython: An extension to eval python3 codes in PHP
- classes