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

后端 未结 4 2165
南方客
南方客 2021-02-08 05:47

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

相关标签:
4条回答
  • 2021-02-08 05:55

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

    0 讨论(0)
  • 2021-02-08 06:05

    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);
    
    0 讨论(0)
  • 2021-02-08 06:12

    It works

    <?php
    
        system("wget -N -O - 'http://google.com")
    
    ?>
    
    0 讨论(0)
  • 2021-02-08 06:14

    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

    0 讨论(0)
提交回复
热议问题