简体   繁体   English

从RSS提要中查找字符串

[英]Finding strings from an rss feed

I am trying to make a system where I gather colour themes from adobe kuler by rss feed and put them into a new format. 我正在尝试建立一个系统,在该系统中,我通过rss feed从adobe kuler收集颜色主题并将其设置为新格式​​。

The rss feed is layed out like this: rss feed的布局如下:

<kuler:themeItem>
   <kuler:themeSwatches>
     <kuler:swatch>
       <kuler:swatchHexColor>

However, I cannot enter any of those tags, due to the colon in the tag. 但是,由于标签中的冒号,我无法输入这些标签中的任何一个。 This: foreach ($item->kuler:themeItem as $item) would return an error because of the colon. 这: foreach ($item->kuler:themeItem as $item)将由于冒号而返回错误。

The simplest way is to remove the namespace indicators from the XML string prior to passing it to the XML parser (the namespace indicators are the strings before the colons; in your case kuler) like so: 最简单的方法是在将XML字符串传递给XML解析器之前从XML字符串中删除名称空间指示符(名称空间指示符是冒号之前的字符串;在您的情况下为kuler),如下所示:

$xmlString = file_get_contents( $feedURL );
$xmlObj = simplexml_load_string( preg_replace( "/(<\/?)[^:]+:([^>]+>)/", "$1$2", $xmlString ) );

Try this XML->Array Funcs 试试这个XML-> Array Funcs

I'd suggest trying that. 我建议尝试一下。

The resulting array looks something like: 结果数组如下所示:

Array
(
    [themeSwatches] => Array
        (
            [swatch] => Array
                (
                    [swatchHexColor] => #000000;
                )

        )

)

Test Code: 测试代码:

require_once('xml2array.php'); // file with the linked to functions

$test = '<kuler:themeItem>
        <kuler:themeSwatches>
                 <kuler:swatch>
                     <kuler:swatchHexColor>
                    #000000;
                     </kuler:swatchHexColor>
            </kuler:swatch>
        </kuler:themeSwatches>
    </kuler:themeItem>
    ';


$a = xmlstr_to_array($test);
print_r($a);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM