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

PHP获取百度最新事件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-21 08:52:051114browse

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>
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