我在一個小的cronjob上使用fsockopen來讀取和解析不同服務器上的提要。對於大多數過去,這很有效。然而,在一些服務器上,我得到的迴應很奇怪的線條,就像這樣:fsockopen的奇怪讀數
<language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> 11 <item> <title> 1f July 8th, 2010</title> <link> 32 http://darkencomic.com/?p=2406</link> <comments> 3e
但是當我打開例如飼料記事本++,它工作得很好,顯示:
<language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item> <title>July 8th, 2010</title> <link>http://darkencomic.com/?p=2406</link> <comments>
...只是爲了顯示摘錄。那麼,我在這裏做錯了什麼,或者這超出了我的控制範圍?我很感激任何想法來解決這個問題。 下面是我使用的檢索,原料中的部分代碼:
$fp = @fsockopen($url["host"], 80, $errno, $errstr, 5); if (!$fp) { throw new UrlException("($errno) $errstr ~~~ on opening ".$url["host"].""); } else { $out = "GET ".$path." HTTP/1.1\r\n" ."Host: ".$url["host"]."\r\n" ."Connection: Close\r\n\r\n"; fwrite($fp, $out); $contents = ''; while (!feof($fp)) { $contents .= stream_get_contents($fp,128); } fclose($fp);
嘿,但我喜歡重新發明輪! ;) 感謝您的信息,這有助於很多! – Ineluki 2010-07-14 13:05:24
那麼,重新發明車輪可以很有趣 - 如果你有很多時間的話;-) ;;別客氣 :-) – 2010-07-14 13:06:31