你可以在Perl文件中包含PHP吗?

Dan*_*der 3 php perl

我有一个由其他人用Perl编写的页面.我不知道Perl,所以我写了一个PHP文件,现在只是来自Perl页面的链接.如果perl页面已经传递了某个变量,我想要做的是将PHP文件嵌入到Perl文件中.如果我正在使用PHP,我可以做到

if ($_GET['sidebar']) include "embedded.php";
Run Code Online (Sandbox Code Playgroud)

我知道有办法在Perl中读取文本文件,但是我可以在Perl文件中包含PHP文件吗?

我认为它不起作用,因为它们是由服务器的不同部分处理的,所以没有很高的期望,但也许某人尝试了类似的东西.

rja*_*lor 14

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

首先,test.pl脚本:

[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;
Run Code Online (Sandbox Code Playgroud)

接下来,test.php脚本:

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

echo "PHP generated this";

?>
Run Code Online (Sandbox Code Playgroud)

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

[root@www1 cgi-bin]# perl test.pl
This is a perl script
This is from PHP:
PHP generated this
Back to perl...
Run Code Online (Sandbox Code Playgroud)


Leo*_*ans 11

PHPPHP :: Interpreter模块,都有一个include方法.尽管我自己也没试过.