可以在Perl文件中包含PHP吗? [英] Can you include PHP in a Perl file?

查看:71
本文介绍了可以在Perl文件中包含PHP吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有其他人用Perl编写的页面.我不认识Perl,所以我写了一个PHP文件,现在它只是来自Perl页面的链接.我想做的是,如果将perl页面传递了某个变量,则将PHP文件嵌入到Perl文件中.如果我都使用PHP,那我就可以做到

I have a page written in Perl by someone else. I don't know Perl, so I wrote a PHP file that right now just links from the Perl page. What I'd like to do is embed the PHP file in the Perl file if the perl page has been passed a certain variable. If I were using PHP for both I could just do

if ($_GET['sidebar']) include "embedded.php";

我知道有几种方法可以在Perl中读取文本文件,但是我可以在Perl文件中包含一个PHP文件吗?

I know there are ways to read text files in Perl, but can I include a PHP file within a Perl file?

我假设它不起作用,因为它们是由服务器的不同部分处理的,因此希望不高,但是也许有人尝试过类似的方法.

I'm assuming it wouldn't work because they're processed by different parts of the server, so no high hopes, but maybe someone's tried something like it.

推荐答案

如果您只是想将PHP脚本的结果输出(HTML等)包括到perl生成的页面中,则可以使用反引号来调用通过php-cli的PHP脚本,如下所示:

If you simply want to include the resulting output (HTML, etc.) of the PHP script into the perl-generated page you can use backticks to call either the PHP script via php-cli, like this:

首先是test.pl脚本:

First, the test.pl script:

[root@www1 cgi-bin]# cat test.pl
#!/usr/bin/perl
print "This is a perl script\n";
my $output = `php test.php`;
print "This is from PHP:\n$output\n";
print "Back to perl...\n";
exit 0;

接下来,是test.php脚本:

Next, the test.php script:

[root@www1 cgi-bin]# cat test.php
<?php

echo "PHP generated this";

?>

这是运行"test.pl"的输出:

Here's the output of running "test.pl":

[root@www1 cgi-bin]# perl test.pl
This is a perl script
This is from PHP:
PHP generated this
Back to perl...

这篇关于可以在Perl文件中包含PHP吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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