How to run wget from php so that output gets displ开发者_Go百科ayed in the browser window?
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);
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
Don't try that on most serversr, they should be blocked from running commands like wget! file_get_contents has just replaced crappy iframe my client insisted on having with this and a quick
<?php
$content = file_get_contents('http://www.mysite.com');
$content = preg_replace("/Comic Sans MS/i", "Arial, Verdana ", $content);
$content = preg_replace("/<img[^>]+\>/i", " ", $content);
$content = preg_replace("/<iframe[^>]+\>/i", " ", $content);
$echo $content;
?>
later to alter the font, images and remove images and iframes etc.... and my site is looking better than ever! (Yes I know my bit of the code isn't brilliant but it's a big improvement for me and removes the annoying formatting!)
It works
<?php
system("wget -N -O - 'http://google.com")
?>
精彩评论