The Artima Developer Community
Sponsored Link

Java Buzz Forum
Write PHP in Perl with PHP::Interpreter

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Write PHP in Perl with PHP::Interpreter Posted: Aug 23, 2005 3:25 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: Write PHP in Perl with PHP::Interpreter
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement

Ever written a Perl application and wished that you could write some PHP in there? Ok, probably not too often.... but now you can!

This came about via Bricolage Now has PHP 5 Templating and how:

And finally—yes, you heard right—Bricolage now supports PHP 5 templating in addition to the existing Perl-based templating architectures (Mason, Template Toolkit, and HTML::Template). So how did we add PHP 5 templating to a mod_perl application? Easy: we hired George Schlossnagle of Omni TI to write PHP::Interpreger, an embedded PHP 5 interpreter. Now anyone can natively execute PHP 5 code from a Perl application. Not only that, but the PHP 5 code can reach back into the Perl interpreter to use Perl modules and objects!

So picture using this Perl in this PHP:

<?php
  $perl = Perl::getInstance();
  $perl->eval("use DBI");
  $perl->eval("use DateTime");
  $dbh = $perl->call("DBI::connect", "DBI", "dbi:SQLite:dbname=dbfile");
  $dbh->do("CREATE TABLE foo (bar TEXT, time DATETIME)");
  $now = $perl->call("DateTime::now", "DateTime");
  $ins = $dbh->prepare("INSERT INTO foo VALUES (?, ?)");
  $ins->execute("This is a test", $now);
  $sel = $dbh->prepare("SELECT bar, time FROM foo");
  $sel->execute();
  $a = array("foo", "bar");
  foreach ($sel->fetch() as $val) {
      echo "$val\n";
  }
  $sel->finish();
  $dbh->do("DROP TABLE foo");
  $dbh->disconnect();
?>

and what about PHP in Perl (Mason)?

<%perl>;
for my $e ($element->get_elements(qw(header para _pull_quote_))) {
    my $kn = $e->get_key_name;
    if ($kn eq "para") {
        $m->print("<p>", $e->get_data, "</p>\n");
    } elsif ($kn eq "header") {
        # Test sdisplay_element() on a field.
        $m->print("<h3>", $burner->sdisplay_element($e), "</h3>\n");
    } elsif ($kn eq "_pull_quote_" && $e->get_object_order > 1) {
        # Test sdisplay_element() on a container.
        $m->print($burner->sdisplay_element($e));
    } else {
        # Test display_element().
        $burner->display_element($e);
    }
}
$burner->display_pages("_page_");
</%perl>

Interesting. If only there were a common platform for dynamic languages that we could all deploy too so George Schlossnagle wouldn't have to go to this trouble!

Read: Write PHP in Perl with PHP::Interpreter

Topic: Looking for a Usenet (NNTP) Reader Previous Topic   Next Topic Topic: &#8220;Even Hell Has Its Standards&#8221;

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use