duancuan6466 2009-01-18 16:05
浏览 18
已采纳

你可以在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";

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.

  • 写回答

4条回答 默认 最新

  • duanli8391 2009-01-18 16:54
    关注

    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:

    First, the test.pl script:

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

    Next, the test.php script:

    [root@www1 cgi-bin]# cat test.php
    <?php
    
    echo "PHP generated this";
    
    ?>
    

    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...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记