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 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?