kmiles has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have several new web sites that use PHP heavily (all of our existing sites use Perl). All I want to be able to do is create a PHP template for output from a Perl program. Template is created, slurp the template into $var, replace with content using regexp, then print STDOUT "Content-type: text/html\n\n$var\n"; Problem is that <?php commands ?> are ignored when dumped this way. I've written the contents to a temp file and then output a html redirect, which works but is very messy and slow. Is there a way to output to STDOUT but have the PHP processed? Thanks for any help!

Replies are listed 'Best First'.
Re: Output PHP
by rafl (Friar) on Jan 09, 2008 at 03:53 UTC
      I've looked at this also. I just haven't been able to figure out how to use it for this case. I was hoping someone could provide an example.
Re: Output PHP
by Cody Pendant (Prior) on Jan 09, 2008 at 06:06 UTC
    Direct system() or exec() call to the PHP executable?

    Their -r flag looks like it's the equivalent of our -e flag so maybe

    system("php -r $var")
    would do it?

    Nobody says perl looks like line-noise any more
    kids today don't know what line-noise IS ...
Use Perl to output PHP template
by kmiles (Initiate) on Jan 10, 2008 at 16:21 UTC
    I posted this question the other day Thanks for the responses. I was able to use LWP::Simple to capture the output of the PHP template to a Perl $var, then do my regexp content replacement inside the $var, then output all to STDOUT.