suppress error using fread()
Posted
by Mikey1980
on Stack Overflow
See other posts from Stack Overflow
or by Mikey1980
Published on 2010-04-23T18:44:56Z
Indexed on
2010/04/23
19:03 UTC
Read the original article
Hit count: 208
php
I wrote a script for screen pops from our soft phone that locates a directory listing for the caller but occasionally they get "Can't read input stream" and the rest of the script quits.
Does anyone have any suggestions on how to suppress error the error message and allow the rest of the script to run? Thanks!
$i=0;
$open = fopen("http://www.411.ca/whitepages/?n=".$_GET['phone'], "r");
$read = fread($open, 9024);
fclose($open);
eregi("'/(.*)';",$read,$got);
$tv = ereg_replace('[[:blank:]]',' ',$got[1]);
$url = "http://www.411.ca/".$tv;
while ($name=="unknown" && $i < 15) { ## try 15 times before giving up
$file = @ fopen($fn=$url,"r") or die ("Can't read input stream");
$text = fread($file,16384);
if (preg_match('/"name">(.*?)<\/div>/is',$text,$found)) {
$name = $found[1];
}
if (preg_match('/"phone">(.*?)<\/div>/is',$text,$found)) {
$phone = $found[1];
}
if (preg_match('/"address">(.*?)<\/div>/is',$text,$found)) {
$address = $found[1];
}
fclose($file);
$i++;
}
© Stack Overflow or respective owner