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.
|