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

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

2005年11月15日-はてなブックマーク

スポンサード リンク
[PR] 英単語を忘却曲線アプリを使って超効率よく記憶する方法
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版があったら日本でもウケそうです。
スポンサード リンク

By.KJ : 2005年11月15日 11:59 livedoor Readerで購読 Twitterに投稿

間違いの指摘をしていただける方はメール、あるいはTwitter/FBでお願いします(クリック)