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
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();\'');

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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