前の記事 «:Flashのバージョンを検出するJavascriptコード
次の記事 »:GTD向けTODOスクリプト

PiP - PythonをPHPコードの中に埋め込む

2005年11月15日

スポンサード リンク
PiP - Python in PHP

To that end, I've written a Python extension for PHP. In short, this extensions allows the Python interpretter to be embedded inside of PHP (think of PHP as the parent language with Python as its child). This allows native Python objects to be instantiated and manipulated from within PHP. There is also initial support for accessing PHP functions and data from within the embedded Python environment.
PHPのエクステンションとしてPythonインタプリタを埋め込んでみました。というものです。

<?php
$a = "test";
$b = true;
$c = 50;
$d = 60.4;

$code = <<<EOD
import php

a = php.var('a')
b = php.var('b')
c = php.var('c')
d = php.var('d')

print a, b, c, d
print a, d / c + b, a
EOD;

py_eval($code);
?>
py_evalでPythonのコードを評価し、実行できる。すごいです。
Perl版があったら日本でもウケそうです。
スポンサード リンク

投稿者 KJ : 2005年11月15日 11:59 | ブックマークに追加する Subscribe with livedoor Reader
間違いの指摘をしていただける方はメールでお願いします


本を執筆しました。