0
我有一個隨機的網址,設置爲PHP字符串,例如:的SimpleXML前檢查它的飼料
$u='http://www.google.com/feedtest/something';
我使用SimpleXML來得到$u
進你將如何確定是否在使用simpleXML下載之前,url是一個feed(RSS,XML,..)嗎?
我有一個隨機的網址,設置爲PHP字符串,例如:的SimpleXML前檢查它的飼料
$u='http://www.google.com/feedtest/something';
我使用SimpleXML來得到$u
進你將如何確定是否在使用simpleXML下載之前,url是一個feed(RSS,XML,..)嗎?
您應該能夠使用get_headers()
(see man page):
$url = 'http://www.example.com';
print_r(get_headers($url, 1));
會給你回下列打印:
Array
(
[0] => HTTP/1.1 200 OK
[Date] => Sat, 29 May 2004 12:28:14 GMT
[Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux)
[Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT
[ETag] => "3f80f-1b6-3e1cb03b"
[Accept-Ranges] => bytes
[Content-Length] => 438
[Connection] => close
[Content-Type] => text/html
)
所以,你可以使用類似:
$headers = get_headers($url, 1);
if($headers['Content-Type'] == 'application/rss+xml') {
// read the file
}
只要您要求這些文件的服務器實際上發送了更改RSS數據的等效響應標頭。
試試吧。看看會發生什麼....你爲什麼要**我們**成爲測試動物? – Neal