tidalik Posted March 4, 2006 Share Posted March 4, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/4052-including-perl-into-php/ Share on other sites More sharing options...
kenrbnsn Posted March 4, 2006 Share Posted March 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4052-including-perl-into-php/#findComment-14069 Share on other sites More sharing options...
tidalik Posted March 4, 2006 Author Share Posted March 4, 2006 [!--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? Quote Link to comment https://forums.phpfreaks.com/topic/4052-including-perl-into-php/#findComment-14088 Share on other sites More sharing options...
kenrbnsn Posted March 4, 2006 Share Posted March 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4052-including-perl-into-php/#findComment-14103 Share on other sites More sharing options...
tidalik Posted March 4, 2006 Author Share Posted March 4, 2006 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... Quote Link to comment https://forums.phpfreaks.com/topic/4052-including-perl-into-php/#findComment-14108 Share on other sites More sharing options...
exeterdad Posted March 4, 2006 Share Posted March 4, 2006 If it's simply a config file.... Make a copy of it and rename it???? Then add your tags. Quote Link to comment https://forums.phpfreaks.com/topic/4052-including-perl-into-php/#findComment-14130 Share on other sites More sharing options...
kenrbnsn Posted March 4, 2006 Share Posted March 4, 2006 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 Link to comment https://forums.phpfreaks.com/topic/4052-including-perl-into-php/#findComment-14165 Share on other sites More sharing options...
exeterdad Posted March 4, 2006 Share Posted March 4, 2006 [!--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] Quote Link to comment https://forums.phpfreaks.com/topic/4052-including-perl-into-php/#findComment-14197 Share on other sites More sharing options...
tidalik Posted March 5, 2006 Author Share Posted March 5, 2006 WOW Ken!! That's fabulous!!!! That's a keeper.Thanks - I owe youSOLVED! Quote Link to comment https://forums.phpfreaks.com/topic/4052-including-perl-into-php/#findComment-14301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.