Jump to content

Archived

This topic is now archived and is closed to further replies.

tidalik

Including Perl into PHP

Recommended Posts

I am hoping to add onto a Perl program. I am not ready to learn Perl yet and rewriting it all in PHP is not an option right now.

I am looking for the best options for getting this to work.

I have a config.pl file I want to include into a PHP file and use the values defined.
At present when I include it I end up with it being passed as if it were a text file and it displays the contents in the browser.

My current feeling is to save the contents to a string, change all the # commenting to either // OR just delete it, but then how to I use the values defined?

Is there a simpler way of doing this, perhaps telling the server to regard the perl file as a php one & not text?

Share this post


Link to post
Share on other sites
What does the file config.pl look like. You might be able to use the function [a href=\"http://www.php.net/parse_ini_file\" target=\"_blank\"]parse_ini_file[/a]().

Ken

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]#!/usr/bin/perl -w

# The following parameters are specified by the user.
# Blah Blah
# about the program
# and such.

$DatabaseName = "superblah";
$DatabaseAccount = "bee";
$DatabasePassword = "bub";
$DatabaseHost = "localhost";

$nMaxSearchResults = 100; # Number of search results returned per page
$szDateFormat = "%d %b %Y";
$szSearchPage = "../search.htm"; # URL for the search page link at the bottom of reports
$szLoginPage = "../login.htm";# URL for the login page - displayed on invalid login
$nPictureGens = 2;# set to the number of generations (starting from parents) to include photos
$szPhotoPath = ""; # this is prefixed to all photo paths
$nPhotoWidth = 150;# Pixel width of photo displayed in Pedigree
$szSuccessLoginPage = "../search.htm";# page which is displayed after successful login
$szFailLoginPage = "../fail_login.htm";# page which is displayed after failed login
$nDaysToKeepLogs = 60;# activity older than this many days is deleted from the logs
$szMailProg = "/usr/sbin/sendmail" ;
$szMailRecipient = "support\@blah.com" ; # make sure to \ escape the @
$szUserFields = "COI~Country of Origin";
$szLoaderPassword = "set";# THIS MUST BE SET
$nConfig = 1;# leave this line as last[/quote]

This is the Config.pl - will the commenting be a problem?

Share this post


Link to post
Share on other sites
If you can put a "<?php" at the start of the perl file and a "?>" at the end, then you can just do an
[code]<?php include('config.pl'); ?>[/code]
and it should work.

Ken

Share this post


Link to post
Share on other sites
I wanted to avoid having the <?php ?> bits because this config.pl file is being used in other Perl scripts - I just wanted to be able to use these settings without having to restate them, and also pass on my PHP file to others who use the original program to without having them to reenter their details.

I'll keep thinking...

Share this post


Link to post
Share on other sites
Try this:
[code]<?php
$config = file('config.pl');
foreach($config as $line) {
    if (substr($line,0,1) != '#')
        eval($line);
}
?>[/code]

You really don't need the "if test".

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=351596:date=Mar 4 2006, 10:15 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 4 2006, 10:15 AM) [snapback]351596[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Try this:
[code]<?php
$config = file('config.pl');
foreach($config as $line) {
    if (substr($line,0,1) != '#')
        eval($line);
}
?>[/code]

You really don't need the "if test".

Ken
[/quote]

Brilliant! I'm going to save that for future use!

[div align=\"center\"][img src=\"http://www.yamahafz1oa.com/forum/images/smilies/worship.gif\" border=\"0\" alt=\"IPB Image\" /][/div]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.