首頁 >php教程 >php手册 >PHP获取百度最新事件

PHP获取百度最新事件

WBOY
WBOY原創
2016-06-21 08:52:051103瀏覽

PHP获取百度最新事件,如下代码:

<ol class="dp-c">
<li class="alt"><span><span class="keyword">function</span><span> getBaiduHotKeyWord()    </span></span></li>
<li><span>{    </span></li>
<li class="alt"><span>    <span class="vars">$templateRss</span><span> = </span><span class="func">file_get_contents</span><span>(</span><span class="string">'http://top.baidu.com/rss_xml.php?p=shijian'</span><span>);    </span></span></li>
<li><span>    If (preg_match(<span class="string">'/<table>(.*)/is'<span>, </span><span class="vars">$templateRss</span><span>, </span><span class="vars">$_description</span><span>)) {    </span><li class="alt"><span>    <span class="vars">$templateRss</span><span> = </span><span class="vars">$_description</span><span>[0];    </span></span></li>
<li><span>    <span class="vars">$templateRss</span><span> = </span><span class="func">str_replace</span><span>(</span><span class="string">"&"</span><span>, </span><span class="string">"&"</span><span>, </span><span class="vars">$templateRss</span><span>);    </span></span></li>
<li class="alt"><span>    }    </span></li>
<li><span>   <span class="vars">$templateRss</span><span> = </span><span class="string">"<?xml  version=\"1.0\" encoding=\"GBK\"?>"</span><span>.trim(</span><span class="vars">$templateRss</span><span>);    </span></span></li>
<li class="alt"><span>   <span class="vars">$xml</span><span> = simplexml_load_String(</span><span class="vars">$templateRss</span><span>);    </span></span></li>
<li><span>   <span class="keyword">foreach</span><span> (</span><span class="vars">$xml</span><span>->tbody->tr </span><span class="keyword">as</span><span> </span><span class="vars">$temp</span><span>) {    </span></span></li>
<li class="alt"><span>    <span class="keyword">if</span><span> (!emptyempty (</span><span class="vars">$temp</span><span>->td->a)) {    </span></span></li>
<li><span>      <span class="vars">$keyArray</span><span> [] = trim((</span><span class="vars">$temp</span><span>->td->a));    </span></span></li>
<li class="alt"><span>    }    </span></li>
<li><span>   }    </span></li>
<li class="alt"><span>   <span class="keyword">return</span><span> </span><span class="vars">$keyArray</span><span>;    </span></span></li>
<li><span> }   </span></li>
            <p style="width:100%;text-align:center;margin:10px 0">

<br>
<br>

</p>
<p style="width:100%;text-align:center;margin:10px 0">

            </p>
<p class="clear"></p>

           </table></span></span></li>
</ol>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn