Slash Boxes
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)

  (email not shown publicly)
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


[ #9678 ]

Kris Boulez of 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:


$robot = 'Book Agent';
$port = 80;
$hosts = Array(
   '' => 'Amazon',
   '' => 'Barnes and Noble',
   '' => '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 = (
   '' => 'Amazon',
   '' => 'Barnes & Noble',
   '' => '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.
More | Login | Reply
Loading... please wait.