mirror of
https://github.com/php-win-ext/phpy.git
synced 2026-03-24 08:52:08 +01:00
854 B
854 B
在 Python 使用 PHP 的功能
在 Python 代码中调用 PHP 的函数。模块名称为 phpy,导入即可。
例子
from php import curl
ch = curl.init("https://www.baidu.com/")
curl.setopt(ch, curl.CURLOPT_RETURNTRANSFER, True)
rs = curl.exec(ch)
print(rs)
在上面的代码中我们使用了 PHP 的 curl 扩展,请求了百度首页。
封装模块
除了直接使用 phpy 模块外,也可以使用反射工具自动生成的封装模块。
生成
php tools/gen-pymod.php
使用
from php import curl
ch = curl.init("https://www.baidu.com/")
curl.setopt(ch, curl.CURLOPT_RETURNTRANSFER, True)
rs = curl.exec(ch)
print(rs)