View Single Post
  #3 (permalink)  
Old 08-07-2007, 12:39 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: How will use perl function in php page?

few more information on Perl Interpreter in PHP

To access the perl interpreter from PHP, you must first create an instance of the Perl class. Its constructor can receive some parameters, but we will omit them at this point. They are necessary for working with perl objects, but not for working with the interpreter itself.

$perl = new Perl();

This line of code creates an instance of the perl interpreter. It is possible to create several instances of the interpreter, but all of them will use the same one internally, so that all code and variables will be shared across instances. The object $perl can be used to execute external perl files, evaluate inline perl code, access perl variables and call perl functions.
External perl files can be loaded using the Perl::require() method. Take a look at the following example:

Example 1 (test1.pl)

print "Hello from perl! "

Example 1 (test1.php)
--------------------
<?php

print "Hello from PHP! ";
$perl = new Perl();
$perl->require("test1.pl");
print "Bye! ";

?>
In this example perl outputs a string directly to the PHP output stream, but in some cases you will want to grab the output as a string and process it with your PHP code. This can be done using the PHP output buffering API:
<?php

ob_start();
$perl = new Perl();
$perl->require("test1.pl");
$out = ob_get_contents();
ob_end_clean();
print "Perl: $out";

?>
__________________
With,
J. Jeyaseelan

Everything Possible

Last edited by Jeyaseelansarc : 08-08-2007 at 07:54 AM.
Reply With Quote