如何从 Perl 调用 PHP 脚本? [英] How can I invoke a PHP script from Perl?

查看:41
本文介绍了如何从 Perl 调用 PHP 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 Perl 脚本调用 PHP 脚本并将其输出作为变量获取?

How can I call a PHP script from a Perl script and get its output as a variable?

推荐答案

使用 反引号运算符:

my $phpOutput = `/usr/bin/php-cli your-script.php`;

请注意,您可能需要编辑路径以指向您的 php 可执行文件.

Note that you may have to edit the path to point to your php executable.

如果您想将输出作为流,您也可以使用管道(Perl <3)open:

If you want to have the output as a stream you can also open with a pipe (Perl <3):

open PHPOUT, "/usr/bin/php-cli your-script.php|";
while (<PHPOUT>) {
  # do something with the current line $_
}

参见 perldoc -f open.

这篇关于如何从 Perl 调用 PHP 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆