tags:

views:

205

answers:

2

How to run wget from php so that output gets displayed in the browser window?

+3  A: 

You can just use file_get_contents instead. Its much easier.

echo file_get_contents('http://www.google.com');

If you have to use wget, you can try something like:

$url = 'http://www.google.com';
$outputfile = "dl.html";
$cmd = "wget -q \"$url\" -O $outputfile";
exec($cmd);
echo file_get_contents($outputfile);
codaddict
-1 sorry but this does not answer the question at all.
Max
+1 It's a perfectly acceptable alternative to trying to run a system command which may be disallowed in the first place.
jasonbar
@Johan: the answer was edited and the second example was added after my comment, so please calm down, ok?
Max
@Max: Sorry missed that (I removed my comment since it's irrelevant)
Johan
+3  A: 

The exec function can be used to run wget. I've never used wget for more then simple file downloads but you would use whatever arguments you give to wget to make it output the file contents. The second parameter/argument of exec will be an array, and this array will be filled line by line with the output of wget.

So you would have something like:

<?php

exec('wget http://google.com/index.html -whateverargumentisusedforoutput', $array);

echo implode('<br />', $array);

?> 

The manual page for exec probably explains this better: http://php.net/manual/en/function.exec.php

Chris Clarke