Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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

like image 956
Svolochenok Avatar asked Mar 27 '10 07:03

Svolochenok


3 Answers

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);
like image 149
codaddict Avatar answered Nov 20 '22 21:11

codaddict


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

like image 39
Absurd Ninja Avatar answered Nov 20 '22 22:11

Absurd Ninja


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!)

like image 1
Iain Sherris Avatar answered Nov 20 '22 23:11

Iain Sherris