Page 1 of 1

Executing PHP script from Perl script

PostPosted: 26. January 2011 22:30
by PStechPaul
In my other post about sending email I showed how I was running a PHP script from Perl using a heredoc and <iframe>. It seemed to work, but actually it processed the HTML after the Perl script had run, so it was useless for what I wanted. Here is what I found to be the proper way to do this:

Code: Select all
#!"\xampp\perl\bin\perl.exe"
my %in = Vars();   # Get the CGI input variables
while ( (my $key, my $value) = each (%in) ) {
    # Write to Raw.htm
    print fLog "Raw: $key -> $in{$key}\n";
    open (fHTMLraw, '>', $HTMLrawfile)
    or HTMLdie ("File error: $!");
    print fHTMLraw $value;
    close fHTMLraw;
    system( '..\php\php HTMLfilter.php' );
    if (-e $HTMLpurefile){
      open (fHTMLpure, '<', $HTMLpurefile);
      $in{$key} = <fHTMLpure>;
      close fHTMLpure; }
    else {
      $in{$key} = 'Purifier error';
      print fLog "Purifier error"; }
    print fLog "Pure: $key -> $in{$key}\n";
    }


The only problem with this is that it pops up a command window for each iteration of the loop. But the results are fine.

There are other more complex but perhaps better ways to do this, and there are solutions for running PHP from Perl as well as running Perl from PHP:
http://devzone.zend.com/article/1712
http://www.cpan.org/modules/by-module/PHP/
http://pecl.php.net/package/perl