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

PHP获取百度最新事件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB원래의
2016-06-21 08:52:051114검색

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으로 문의하세요.