Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

inkdroid (3294)

inkdroid
  (email not shown publicly)
http://www.inkdroid.org/
AOL IM: inkdroid (Add Buddy, Send Message)
Yahoo! ID: summe_e (Add User, Send Message)
Jabber: inkdroid

inkdroid is a person, not a robot. however, inkdroid likes ink. inkdroid likes perl too.

Journal of inkdroid (3294)

Monday December 30, 2002
01:52 PM

PHP::Include

[ #9678 ]

Kris Boulez of london.pm wrote a few weeks ago about parsing simple PHP from Perl, which got me to thinking about a module that would allow you to include PHP files from Perl. This led to PHP::Include which was uploaded to CPAN yesterday.

At the moment it only allows you to include very simple PHP: scalar, array and hash assignments. But it could be useful for Perl applications that need to share configuration data with PHP. The real work is done by Filter::Simple and Parse::RecDescent. PHP::Include was designed so that the more adventurous/knowledgeable could extend the grammar to parse more of PHP.

So given a PHP file "file.php" which contains:

<?php

$robot = 'Book Agent';
$port = 80;
$hosts = Array(
   'www.amazon.com' => 'Amazon',
   'www.bn.com' => 'Barnes and Noble',
   'www.bookpool.com' => 'BookPool'
);
$times = Array( 10,12,14,16,18 );

?>

...and a Perl program like this

use PHP::Include;
include_php_vars( 'file.php' );

The Perl code will be rewritten to be:

use PHP::Include;
my $robot = 'Book Agent';
my $port = 80;
my %hosts = (
   'www.amazon.com' => 'Amazon',
   'www.bn.com' => 'Barnes & Noble',
   'www.bookpool.com' => 'BookPool'
);
my @times = ( 10,12,14,16,18 );

One nice thing is that PHP::Include established the PHP top level namespace on CPAN; so there is a nice home for new modules that glue the two languages together if people are interested.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.