Home >Backend Development >PHP Tutorial > PHP 调用新浪滚动资讯

PHP 调用新浪滚动资讯

WBOY
WBOYOriginal
2016-06-13 12:58:27879browse

PHP 调用新浪滚动新闻

本帖最后由 a999888789 于 2012-11-30 16:06:44 编辑 http://roll.news.sina.com.cn/interface/rollnews_ch_out_interface.php?col=90

程序需要用PHP调用新闻,以URL:title的格式输入~~调出前10条新闻
如何搞呢?
------解决方案--------------------
楼主,先提供一个js 版的先用着,php 版的有点折腾,主要是sina 的js 响应不是特别标准.无法直接用json_decode 来处理.
<br />
<script src="http://roll.news.sina.com.cn/interface/rollnews_ch_out_interface.php?col=90"></script><br />
<script type="text/javascript"><br />
<br />
        function addItem(title,url)<br />
        {<br />
            var html = '<a href="'+url+'" >'+title+'</a><br/>';<br />
            document.getElementById("demo_content").innerHTML += html;<br />
        }<br />
<br />
        function init()<br />
        {<br />
            var listdata = jsonData.list;<br />
            //   console.log( listdata );<br />
            var title ='';<br />
            var url = '';<br />
<br />
            for(var item in listdata){<br />
                title = listdata[item].title;<br />
                url = listdata[item].url;<br />
                // alert(title);<br />
                addItem(title,url)<br />
            }<br />
<br />
        }<br />
</script><br />
<body onload="init()"><br />
<div id = 'demo_content'>here is the content<hr/></div><br />
</body><br />
    <br />
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn