PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hm2k
Forum Newbie
Posts: 3 Joined: Fri Jan 21, 2005 4:49 pm
Post
by hm2k » Fri Jan 21, 2005 4:53 pm
Code: Select all
$xurl = "http://www.".$domain."/";
$handle = fopen($xurl, "r");
$xhtml = '';
while (!feof($handle)) {
$xhtml .= fread($handle, 1024);
}
fclose($handle);
When I use this to lookup a domain that does not resolve, I get lots of errors such as:
Warning: fopen(): php_network_getaddresses: gethostbyname failed
Warning: fopen(
http://www.superman.co.uk/ ): failed to open stream: No error
How can I avoid this problem?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 21, 2005 4:56 pm
use the error control operators.
hm2k
Forum Newbie
Posts: 3 Joined: Fri Jan 21, 2005 4:49 pm
Post
by hm2k » Fri Jan 21, 2005 5:09 pm
I have slighly modified the script:
Code: Select all
$xurl = "http://www.".$domain."/";
$handle = @fopen($xurl, "r");
if (error_reporting() == 0) return;
$xhtml = '';
while (!feof($handle)) {
$xhtml .= fread($handle, 1024);
}
fclose($handle);
However I am still getting errors:
Warning: feof(): supplied argument is not a valid stream resource in ~\x.php on line 49
Warning: fread(): supplied argument is not a valid stream resource in ~\x.php on line 50
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 21, 2005 5:10 pm
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
$domain = 'superman.co.uk';
$xurl = "http://www.".$domain."/";
$handle = @fopen($xurl, "r");
$xhtml = '';
if($handle !== false)
{
while (!feof($handle)) {
$xhtml .= fread($handle, 1024);
}
fclose($handle);
}
else
{
$xhtml = 'failed to open page';
}
echo $xhtml;
?>sure works..