Here begins a ramble.
One way is to make a Perl script containing your function which accepts
a variable on the command line (%ARG), so that, if called on the command
line as follows:
perl script.pl your_variable
it will print the data to standard out after running it through the Perl
subroutine.
You can call the Perl script using PHP's passthru() function and get the
output of the script into a PHP variable:
$result=passthru("perl script.pl your_variable");
Now the difficulty lies in passing the key/value array on the command
line. PHP has a serialize() and unserialize() function, which converts
data structures to and from a string. Perl has no such thing but this
Perl module will do the trick:
http://hurring.com/code/perl/serialize/
So PHP serializes the data, calls the Perl script with the serialized
data on the command line, Perl unserializes the data, runs it through
the function, serializes the result, prints it to the standard out, PHP
receives the serilazed data, unserializes it and voila.
You'll need to consider security to make sure nothing dangerous can get
executed by the passthru() function. Take a look at escapeshellarg() and
escapeshellcmd().
Additionally, a command line has a maximum length (I'm unsure what it is
off the top of my head). If this is a problem, you could pass the data
in a file which can be shared between PHP and Perl.
Alternatively, rewrite your Perl function in PHP.
- Aug 19 Sun 2007 23:34
PHP 呼叫 Perl ,接下來要找PHP和Perl去讀相同的文字設定檔
文章來源
全站熱搜
留言列表
禁止留言