lopes_andre Posted February 5, 2010 Share Posted February 5, 2010 Hi, I have one string with $string = '1,2,3,4,5,6,7'; I need to show this in a RSS feed like: <category><![CDATA[1]]></category> <category><![CDATA[2]]></category> <category><![CDATA[3]]></category> <category><![CDATA[4]]></category> <category><![CDATA[5]]></category> <category><![CDATA[6]]></category> <category><![CDATA[7]]></category> How can I do this? Using implode or explode? Best Regards, Link to comment https://forums.phpfreaks.com/topic/191099-how-to-list-this-string/ Share on other sites More sharing options...
JAY6390 Posted February 5, 2010 Share Posted February 5, 2010 $arr = explode(',', $string); $rss = ''; foreach($arr as $v) { $rss .= sprintf('<category><![CDATA[%d]]></category>', $v); } echo $rss; Link to comment https://forums.phpfreaks.com/topic/191099-how-to-list-this-string/#findComment-1007660 Share on other sites More sharing options...
harristweed Posted February 5, 2010 Share Posted February 5, 2010 $string = '1,2,3,4,5,6,7'; $$string_array=explode(",", $string); foreach ($$string_array as $value) { echo"<category><![CDATA[$value]]></category>\n"; } Link to comment https://forums.phpfreaks.com/topic/191099-how-to-list-this-string/#findComment-1007663 Share on other sites More sharing options...
JAY6390 Posted February 5, 2010 Share Posted February 5, 2010 ^ You need to remove the extra $ before the $$string_array vars above Link to comment https://forums.phpfreaks.com/topic/191099-how-to-list-this-string/#findComment-1007664 Share on other sites More sharing options...
harristweed Posted February 5, 2010 Share Posted February 5, 2010 Ye I just noticed that! It is a bit late at night here! Link to comment https://forums.phpfreaks.com/topic/191099-how-to-list-this-string/#findComment-1007666 Share on other sites More sharing options...
lopes_andre Posted February 5, 2010 Author Share Posted February 5, 2010 Hi, Thanks for the reply. It is working. Best Regards, Link to comment https://forums.phpfreaks.com/topic/191099-how-to-list-this-string/#findComment-1007671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.