Php Save fopen Result To A String

故事扮演 提交于 2019-12-06 05:20:47
$handle = @fopen("http://www.example.com/", "r");

$buffer = '';
if ($handle) {
    while (!feof($handle)) {
      $buffer .= fgetss($handle, 5000);
    }

    fclose($handle);
}
Ale

Try file_get_contents() :

$buffer = file_get_contents("/my/file.txt");

The easiest way is to use file_get_contents:

$buffer = file_get_contents("http://www.exemple.com");

$buffer is itself a string. instead of printing it using echo just concatenate it there and print it or use it with all together after the loop ends.

$buffer = '';
if ($handle) {
    while (!feof($handle)) {
      $buffer .= fgetss($handle, 5000);
    }

    fclose($handle);
}

//print the whole stuff:
echo $buffer;

And if you want to get all the stuffs only no other processing try using:

file_get_contents

$handle = @fopen("http://www.example.com/", "r");
$buffers = array();

    if ($handle) {
        while (!feof($handle)) {
            $buffers[] = fgetss($handle, 5000);

        }

        fclose($handle);
    }


print_r ( $buffers );
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!