Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php Save fopen Result To A String

Tags:

php

fgets

fopen

How can I get the "$buffer" value into a string, and use it outside the fopen and fclose functions? Thanks.

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

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

      echo $buffer ;
    }

    fclose($handle);
}
like image 768
JennyL Avatar asked Apr 09 '26 18:04

JennyL


2 Answers

Try file_get_contents() :

$buffer = file_get_contents("/my/file.txt");
like image 51
Ale Avatar answered Apr 11 '26 07:04

Ale


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

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

    fclose($handle);
}
like image 23
Emil Vikström Avatar answered Apr 11 '26 08:04

Emil Vikström



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!