Created
May 14, 2012 09:39
-
-
Save trmtsy/2692966 to your computer and use it in GitHub Desktop.
PHPでXML取得
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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