Home  >  Article  >  Backend Development  >  !怎么用PHP获取RSS阅读器里CDATA部分的内容

!怎么用PHP获取RSS阅读器里CDATA部分的内容

WBOY
WBOYOriginal
2016-06-13 13:39:36874browse

紧急求助!!~如何用PHP获取RSS阅读器里CDATA部分的内容
如题~
阅读器地址:http://rss.weather.gov.hk/rss/CurrentWeather_uc.xml
我要获取CDATA里温度,紫外线,相对湿度等内容,该如何搞定~?



------解决方案--------------------

PHP code
$str=file_get_contents('http://rss.weather.gov.hk/rss/CurrentWeather_uc.xml');
preg_match('/\[CDATA\[\s*<p>(.*)</p><p>/Uis',$str,$match);
print_r($match[1]);
<br><font color="#e78608">------解决方案--------------------</font><br>互联网真是好东西啊!参考文档:搜索“用simpleXML 如何读取 中的内容呢”</p>
PHP code
$url = 'http://rss.weather.gov.hk/rss/CurrentWeather_uc.xml';

$xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA); 

print_r($xml->channel->item->description); <div class="clear">
                 
              
              
        
            </div>
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