Re: PHP with C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 9, 2008 at 9:11 AM, R B <rbpphp@xxxxxxxxx> wrote:
> Hi,
> I have a C++ script containing the function hello(x, y, z)
>
> I want to access this C++ function from PHP, and output with PHP the return
> information.
>
> How can i do this?

    The cheating, quickest, easiest way, would be to write the
function into a portable C++ script, compile it to binary form, and
pass `x`, `y`, and `z` as argv[]'s via PHP's exec() function, like so:

<?php
$ret = null;
// In the exec() call below, note the quotes around special characters
and spaces.
exec('./cpp-binary argument1 argument2 "argument three?"',$ret,$err);
if(count($ret) > 1) {
    foreach($ret as $r) {
        echo $r."<br />\n";
    }
} elseif(count($ret) == 1) {
    echo $ret[0]."<br />\n";
} else {
    echo "Nothing returned by exec()!  Error Level: ".$err."<br />\n";
}
?>

-- 
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux