Skip to content

Instantly share code, notes, and snippets.

@trmtsy
Created May 14, 2012 09:39
Show Gist options
  • Save trmtsy/2692966 to your computer and use it in GitHub Desktop.
Save trmtsy/2692966 to your computer and use it in GitHub Desktop.
PHPでXML取得
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP XML</title>
</head>
<body>
<?php
function readXml(){
// XMLリクエストURL
$req = null;
// HTML表示用
$echoHtml = null;
// RSS配信用のxmlファイルを取得
$req = "http://gree.jp/becky_g/blog/571f7336b603c5bb0b79d2ce91d1a4b7.rdf";
$xml = simplexml_load_file($req);
// XMLの中身が見たい時、ダンプ表示
/*
echo "<pre>";
var_dump ($xml);
echo "</pre>";
*/
$echoHtml = "<div>ブログタイトル:".$xml->channel->title."</div>";
foreach($xml->channel->item as $item) {
$echoHtml .= "<hr />";
$echoHtml .= "<div>".$item->title."</div>";
$echoHtml .= "<div><a href='".$item->link."'>".$item->link."</a></div>";
$echoHtml .= "<div>".$item->pubDate."</div>";
}
return $echoHtml;
}
echo readXml();
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment