How can I invoke a PHP script from Perl?

前端 未结 3 881
刺人心
刺人心 2021-01-12 18:40

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

3条回答
  •  长情又很酷
    2021-01-12 19:32

    Using the backtick operator:

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

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

    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 () {
      # do something with the current line $_
    }
    

    See perldoc -f open.

提交回复
热议问题