Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Because PHP sucks: escape to Perl.

by Juerd (Abbot)
on Feb 06, 2006 at 12:37 UTC ( [id://528203] : CUFP . print w/replies, xml ) Need Help??

Add these three lines to a PHP script to make it a Perl script instead. (Performs badly, doesn't support POST via STDIN, etcetera, but still the end result is more usable than PHP, IMO.)
<? $f = escapeshellarg($_SERVER[SCRIPT_FILENAME]); list($h, $b) = preg_split("/\n\n/", `perl -x $f`,2); foreach (preg_split("/\n/", $h) as $_) header($_); echo $b; exit; ?> #!/usr/bin/perl print "Content-Type: text/plain\n\n"; print "perl++\n" for 1..10;

Replies are listed 'Best First'.
Re: Because PHP sucks: escape to Perl.
by ambrus (Abbot) on Feb 06, 2006 at 20:16 UTC

    Wouldn't it be better to use perl -x instead of perl -e and eval?

      Wouldn't it be better to use perl -x instead of perl -e and eval?

      Certainly. I forgot all about -x. Thanks for the suggestion; I've updated the snippet.

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: Because PHP sucks: escape to Perl.
by Aristotle (Chancellor) on Feb 20, 2006 at 00:02 UTC

    FWIW: I use a very similar trick all the time in conjunction with SSI, where the polyglot ends up looking like this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"> <head> <title>foobar</title> </head> <body> <!--#exec cmd="perl -x $SCRIPT_FILENAME" --> </body> </html> <!--#if expr="0 = 1" --> #!/usr/bin/perl # generate page body here __END__ <!--#endif -->

    It’s actually quite neat as a crude templating system when the script-generated part of the page has little to no variation in markup structure (f.ex. just a simple table or list).

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://528203]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-02-06 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found