Jump to content

Calling php 4 from within php 5


freak1321

Recommended Posts

My hosting company offers both php 5 and 4.  I use php 5.  I want to know how to access a php 4 program (or class).  It's ffmpeg-php and I want to access this code in php 4

 

$ffmpegObj = new ffmpeg_movie($filetmp);

$duration = $ffmpegObj->getDuration();

 

ffmpeg-php is only available on php 4 so basically I need to call this function from within php 5.  I was guessing something like:

 

$test = exec("/usr/bin/php -r '$ffmpegObj = new ffmpeg_movie($filetmp);$duration = $ffmpegObj->getDuration();'");

echo $test;

 

but that doesn't work - any ideas anyone? Seems like a tough question...  :'(

Link to comment
https://forums.phpfreaks.com/topic/64789-calling-php-4-from-within-php-5/
Share on other sites

You have a problem there in that the code in double quotes will have variable substitution done BEFORE being passed to php4.  Try enclosing it in single quotes instead.  You will need to escape single quotes within the string also.  Eg.

 

$test = exec('/usr/bin/php -r \'$ffmpegObj = new ffmpeg_movie($filetmp);$duration = $ffmpegObj->getDuration();\'');

Your right about the problem with the quotation marks (or maybe its something else)... I can't even get any of these to work - could anyone come up with a simple working example?

 

$test = system('/usr/bin/php -r \'echo "hi";\'');

echo $test;

 

OR

$st = 'hello';

$test = system('/usr/bin/php -r \'echo $st;\'');

echo $test;

 

OR

 

$st = 'hello';

$test = system('/usr/bin/php -r \'echo '.$st.'\'');

echo $test;

 

Here you go:

 

$st = 'hello';
$command = '/usr/bin/php -r \'echo "'.$st.'";\'';
print "About to execute $command\n";
$test = system($command);
echo $test;

 

Much better to print out the command before executing, so you can visually inspect it.  Dealing with shell escaping is a hassle though, for any more complicated code.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.