mirror of
https://github.com/php-win-ext/phpy.git
synced 2026-03-25 09:22:21 +01:00
40 lines
914 B
Markdown
40 lines
914 B
Markdown
# Using PHP functionality in Python
|
|
|
|
Call PHP functions in Python code. The module name is `phpy`, which can be imported.
|
|
|
|
- [List of functions](function.md)
|
|
- [Object operations](object.md)
|
|
- [Class operations](class.md)
|
|
- [Reference types](reference.md)
|
|
- [Encapsulated modules](module.md)
|
|
|
|
|
|
## Example
|
|
```python
|
|
from php import curl
|
|
|
|
ch = curl.init("https://www.baidu.com/")
|
|
curl.setopt(ch, curl.CURLOPT_RETURNTRANSFER, True)
|
|
rs = curl.exec(ch)
|
|
print(rs)
|
|
```
|
|
|
|
In the above code, we use the `curl` extension of PHP to request the homepage of Baidu.
|
|
|
|
## Encapsulated modules
|
|
In addition to using the `phpy` module directly, you can also use encapsulated modules generated by reflection tools.
|
|
|
|
### Generation
|
|
```shell
|
|
php tools/gen-pymod.php
|
|
```
|
|
|
|
### Usage
|
|
```python
|
|
from php import curl
|
|
|
|
ch = curl.init("https://www.baidu.com/")
|
|
curl.setopt(ch, curl.CURLOPT_RETURNTRANSFER, True)
|
|
rs = curl.exec(ch)
|
|
print(rs)
|
|
``` |