Last active
September 6, 2015 14:17
-
-
Save Momijinn/62d1ce3405aa038046fe to your computer and use it in GitHub Desktop.
PHPでGoogleが提供しているニュースを解析する
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
<?php | |
/* | |
Create date: 2015/09/06 | |
implementafor: K.Takano | |
HP: http://miyakawamomiji.blogspot.jp/ | |
*/ | |
//引数を持ってくる | |
if (isset($_GET['name'])) { | |
$topics_name = htmlspecialchars($_GET['name'], ENT_QUOTES, 'utf-8'); | |
}else{ | |
//引数が指定されていない場合はrssを持ってくる | |
$topics_name = "rss"; | |
} | |
$topics = "http://news.google.com/news?hl=ja&ned=us&ie=UTF-8&oe=UTF-8&output=rss&topic=".$topics_name; | |
$data1 = file_get_contents($topics); | |
$data2 = simplexml_load_string($data1); | |
/* 解析 */ | |
foreach ($data2 as $key1 => $value1) { | |
foreach ($value1 as $key2 => $value2) { | |
foreach ($value2 as $key3 => $value3) { | |
if ($key3 == "description") { | |
print $value3; | |
print "<br>"; | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PHPでGoogleが提供しいているニュースを解析してみました。
引数を与えてあげると色々なニュースを取得することができます。
example:
http://localhost/php/rss/Google_RSS_ver1.php?name=p
他にも
ir:ピックアップ
y:社会
w:国際
b:ビジネス
p:政治
e:エンタメ
s:スポーツ
t:テクノロジー
po:話題のニュース
が取得できます