読者です 読者をやめる 読者になる 読者になる

Wordpress用RSS取得用PHP

function rssDate($format,$rssDate){
    date_default_timezone_set('Asia/Tokyo');
    return date($format, strtotime($rssDate));
}
function midori_c7_page($url=""){
    $rss = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
	$html="";
	foreach ($rss->channel->item as $item) {
		$date = rssDate('Y-m-d', $item->pubDate);
		$title = $item->title;
		if(strcmp($title, "")==0)$title = "No Name";
		$link = $item->link;
		$content=$item->children('content', true)->encoded;
		$html.= "<dl><dt>".$date."</dt><dd><a href=\"".$link."\">".$title."</a></dd><dd>".$content."</dd></dl>";	}
        echo $html;
}
function backup_url($url,$name="temp_data"){
	$fp = fopen("get_time.txt","r");
	flock($fp,LOCK_SH);
	$line = fgets($fp);
	flock($fp,LOCK_UN);
	fclose($fp);
	if(time()-$line>20 ||!file_exists($name))
		if($FH=fopen($url,"rb")){
			$filename=$name;
			$content=stream_get_contents($FH);
			fclose($FH);
			file_put_contents($filename,$content);
			$line=time();
			$fp = fopen("get_time.txt","w");
			flock($fp,LOCK_EX);
			fputs($fp,$line);
			flock($fp,LOCK_UN);
			fclose($fp);
	}
}
backup_url("http://ここにwordpressrssリンクを","temp_data");
echo '';
midori_c7_page("temp_data");

 こんな感じ。