0

http://www.example.com/pageView?test=111&test2=999 -> 数据加载和工作..

189 <?php
190 $handle = @fopen("http://www.example.com". htmlspecialchars($_GET["test"]) ."/".     htmlspecialchars($_GET["test2"]) .".txt", "r");
191    while (!feof($handle))
192 {
193 $buffer = fgets($handle, 4096);
194
195 if (strlen(trim($buffer)) > 0){
196
197 list($a,$b,$c,$d,$e,$f,$g,$h,$i,$j)=explode(",",$buffer);
198
199 $items[] = array('col1' => $a,'col2' => $b,'col3' => $c,'col4' => $d,'col5' => $e,'col6' => $f,'col7' => $g,'col8' => $h,'col9' => $i,'col10' => $j);

200 }
201 }
202 ?>

http://www.example.com/pageView?test&test2= -> 没有加载.. 这是正常的,但这个错误在页面中..

Warning: feof(): supplied argument is not a valid stream resource in /home/---/public_html/---/---.php on line 191

Warning: fgets(): supplied argument is not a valid stream resource in /home/---/public_html/---/---.php on line 193

如何显示警告信而不是错误页面?

4

1 回答 1

1

检查 的返回值fopen。如果在读取过程中出现错误,您将得到 $handle 等于 false,但您需要将“流资源”传递给eof

if($handle === false) {
    print 'Err found';
}
else {
   while(!eof($handle)) ...
}
于 2013-07-21T20:23:15.300 回答