using a php class in perl

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

using a php class in perl

Post by thomas777neo »

Is it possible

If so, how the heck would you do it.

I have an encryption/decryption function in php using mcrypt. My perl version doesn't support the older mcrypt modules for it. So I couldn't convert the functions to perl, so I want to use it directly.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

write the complete script in php, and then call it from perl with system/exec...

Code: Select all

@result = `php somescript.php`;
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

Code: Select all

@result = `php somescript.php`;
So if I had a function in a class:

Code: Select all

class exampleClass
{

    function example($exampleVar)
    {
        return trim($exampleVar);
    }
}
How would I from your example, create the new object, then execute the function and return the value?

Apologies, if it is a stupid question (I see that it puts the command output into an array, I don't know what to do with it afterwards)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

could would look like (untested)

Code: Select all

require_once('example.class.php');

$example = new example;
$result = $example->example($argv[1]);
echo $result

Code: Select all

#!/usr/bin/perl -w
@result = `php-cli somescript.php somevalue`;
print $resultї0];
Post Reply