Translate php to python

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.

Convert PHP code to Python under CGI (beta)

License

nicolasrod/php2python

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.

Читайте также:  Сервер mod css content

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

Convert PHP code to Python running under CGI (beta).

$ php composer.phar install $ python3 -m pip install -r requirements.txt 

If you have composer / pip installed globally:

$ composer install $ pip3 install -r requirements.txt 

Converting WordPress source code to Python

In the folder ./wordpress-5.4 there’s a copy of WP and its convertion with the tool:

$ python3 php2py.py --keep-ast ./wordpress-5.4 

This produces *.py files, the *.ast (because —keep-ast is used) and if there’s any error (which should be at the moment) *.errors.txt files.

In order to run the converted files you need to specify the full path of the PHP compatibility library in the PHP2PY_COMPAT environmental variable:

$ cd ./wordpress-5.4 $ PHP2PY_COMPAT=$HOME/php_compat.py python3 index.py 

There are a few things left to finish in order to get a complete working converting without having to edit to converted code. I was waiting to tackle those before publishing the code but I’m not having much spare time left these days.

Any PRs and/or comments are more than welcome.

  • Complete implementation of AST nodes transformation.
  • Address limitations of Python language
  • Finish implementing all of the supporting PHP functions to run WordPress.
  • Rearrange AST nodes to simplify conversion.
  • Refactor converted code to output Flask/Django code instead. Requires an overhaul of the import mechanism.

Copyright Nicolás Rodriguez (nicolasrod@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the «Software»), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Convert PHP code to Python under CGI (beta)

Источник

Translate php to python

This free online converter lets you convert code from PHP to Python in a click of a button. To use this converter, take the following steps —

  1. Type or paste your PHP code in the input box.
  2. Click the convert button.
  3. The resulting Python code from the conversion will be displayed in the output box.

Key differences between PHP and Python

Characteristic PHP Python
Syntax PHP syntax is similar to C and Perl. Python syntax is designed to be readable and straightforward.
Paradigm PHP is primarily a procedural language, but it also supports object-oriented programming. Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming.
Typing PHP is a loosely typed language. Python is a strongly typed language.
Performance PHP is generally faster than Python for web development. Python is slower than PHP for web development, but it is faster for scientific computing and data analysis.
Libraries and frameworks PHP has a large number of frameworks and libraries for web development, such as Laravel and Symfony. Python has a vast collection of libraries and frameworks for various purposes, such as Django and Flask for web development, NumPy and Pandas for data analysis, and TensorFlow and PyTorch for machine learning.
Community and support PHP has a large and active community with many resources and support options available. Python has a massive and supportive community with many resources and support options available.
Learning curve PHP has a relatively low learning curve and is easy to learn for beginners. Python has a low learning curve and is easy to learn for beginners, with a focus on readability and simplicity.

Источник

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.

Run Converted PHP Codes in Python with the Speed of Compiled-C using this PHP-to-Python syntax emulation library in Cython

License

wordpy/pyx

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

Run Converted PHP Codes in Python at the Speed of Compiled-C

pyx.php is a Cython compiled module that you can use to convert or translate 99% of most common PHP source codes to pure Python. In another words, it is a PHP-to-Python syntax emulation library in Cython.

The converted Python codes only require a Python 3.x interpreter, the modules in the pyx repository, and some standard Python libraries. PHP interpreter is not needed at all.

If we have already translated most of the WordPress core and other scripts from PHP to Python using pyx.php , you can convert almost any PHP code into Python.

With the speed of compiled Cython, running Python code translated from PHP using pyx.php might be even faster than running the original PHP code in the same computer.

$ git clone https://github.com/wordpy/wordpy/ ls -la wordpy/pyx 
$ git clone https://github.com/wordpy/pyx/ 

You can download older version from your browser or from Linux shell:

$ wget https://wordpy.com/pyx/pyx.tgz $ tar xvfpz pyx.tgz 

Currently, pyx.php is only available for Python 3.x running 64-bit Linux. Python 2.x, Mac, or other platforms can be compiled when there are many requests.

>>> import pyx.php as Php; array = Php.array >>> arr1 = array( (0,'1-0'),('a','1-a'),('b','1-b'),) >>> arr2 = array( (0,'2-0'),( 1,'2-1'),('b','2-b'),('c','2-c'),) >>> arr1 + arr2 # same as: Php.array_plus(arr1, arr2), see below >>> Php.array_merge(arr1, arr2) >>> import pyx.php as Php; array = Php.array >>> Arr0 = array() # Arr0._obj is an empty OrderedDict() >>> Arr1 = array( ('a',11), 'zzz', (99,99), 22, 33, (2,22) ) >>> Arr1 array(6) < ['a']=> 11 [0]=> zzz [99]=> 99 [100]=> 22 [101]=> 33 [2]=> 22 > 

zip() works for array with different len .

>>> for i,j in zip( array(1,2,3,4), array(11,22,33) ): . print(i,j) 1 11 2 22 3 33 >>> for i,j in zip( array(1,2), array(11,22,33) ): . print(i,j) 1 11 2 22 

Why convert from PHP to Python?

If you ask this question, you probably shouldn’t use pyx.php . There is nothing wrong with PHP, except that it’s not Python. So it’s not Pythonic!

If you often have to go between the Python world and the PHP world (WordPress, Drupal, or other PHP framework), you can feel my pains for not being able to use tons and tons of native Python libraries with ease, such as SQLAlchemy, Machine Learning, Deep Learning such as TensorFlow, etc.

PHP frameworks such as WordPress do offer xml-rpc, wp-api, wp-cli, and other APIs to interface with Python and other languages. However, preparing Python programs for such APIs and having PHP to interface with the API on the other end is error prone, not robust, hard to troubleshoot on both ends, and not scalable. Hence, enterprises, web, or big-data applications cannot rely on those APIs for high-speed and high-volume Web applications and large scale data sets.

About

Run Converted PHP Codes in Python with the Speed of Compiled-C using this PHP-to-Python syntax emulation library in Cython

Источник

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.

alquerci / php2py Public archive

Convert PHP code to Python code

License

alquerci/php2py

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

Convert PHP code to Python code.

PHP 5.3.3 or above (at least 5.3.4 recommended to avoid potential bugs)

Fork the project, create a feature branch, and send us a pull request.

To ensure a consistent code base, you should make sure the code follows the Coding Standards which we borrowed from Symfony.

If you would like to help take a look at the list of issues.

See the list of contributors who participated in this project.

This library is licensed under the MIT License — see the LICENSE file for details

You can run the unit tests with the following command:

php composer.phar install --dev phpunit

About

Convert PHP code to Python code

Источник

Оцените статью