Cross Reference: /yui3/src/node-focusmanager/docs/assets/news.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
function getFeed($sFeed) {
$params = array(
"q" => ('select title,link from rss where url="http://rss.news.yahoo.com/rss/".$sFeed.'""),
"format" => "json"
);
$encoded_params = array();
foreach ($params as $k => $v) {
$encoded_params[] = urlencode($k)."=".urlencode($v);
}
$url = "http://query.yahooapis.com/v1/public/yql?".implode("&", $encoded_params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$rsp = curl_exec($ch);
curl_close($ch);
if ($rsp !== false) {
$rsp_obj = json_decode($rsp, true);
$results = $rsp_obj["query"]["results"]["item"];
$list = ""; // HTML output
$nResults = count($results);
if ($nResults > 10) {
$nResults = 9;
}
for ($i = 0; $i<= $nResults; $i++) {
$result = $results[$i];
$list.= <<< END_OF_HTML
<li>
<a href="{$result["link"]}"><q>{$result["title"]}</q></a>
</li>
END_OF_HTML;
}
return ("<ul>" . $list . "</ul>");
}
}
?>