【发布时间】:2013-09-09 10:46:52
【问题描述】:
我正在尝试从 XML Feeds 中获取页面标题。
我以http://feeds.gawker.com/lifehacker/full 为例,使用下面的代码可与其他网站一起使用,但对于Lifehacker,它似乎忽略了关闭</title> 标记,并且console.log 显示了xml 的全部内容开场后<title>
function getTitle($Url){
$str = file_get_contents($Url);
if(strlen($str)>0){
preg_match("/\<title\>(.*)<\/title\>/",$str,$title);
return $title[1];
}
}
$feed = 'http://feeds.gawker.com/lifehacker/full';
$pagetitle = getTitle($feed);
谢谢
【问题讨论】:
标签: php xml xml-parsing