Jump to content

fopen


sanchez77

Recommended Posts

Hi Everyone,

 

For a long time i have been using fopen to read a web page and then display it on my page. But recently, it stopped working.

 

Does anyone know an alternative that I can use?

 

My code is below.

 

<?php

$filename="http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/an/anz451.txt";
$fp = fopen($filename,'r');

while($line=fgets($fp))
{
print $line."<br>";
}

fclose($fp);

?>

Link to comment
https://forums.phpfreaks.com/topic/179977-fopen/
Share on other sites

Example 1. GET example

<?php
$r = new HttpRequest('http://example.com/feed.rss', HttpRequest::METH_GET);
$r->setOptions(array('lastmodified' => filemtime('local.rss')));
$r->addQueryData(array('category' => 3));
try {
    $r->send();
    if ($r->getResponseCode() == 200) {
        file_put_contents('local.rss', $r->getResponseBody());
    }
} catch (HttpException $ex) {
    echo $ex;
}
?>

Example 2. POST example

<?php
$r = new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST);
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
$r->addPostFile('image', 'profile.jpg', 'image/jpeg');
try {
    echo $r->send()->getBody();
} catch (HttpException $ex) {
    echo $ex;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949452
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.