Hi Here is another PHP problem I have. I am trying to clean up an RSS feed so that I can get a list of the domains. I have the general idea of what to do but just can't do the PHP. Basically it would get the text between the <title></title> and echo it in a list. But how do you do that? here is the RSS feed I am using: <?xml version="1.0"?> <rss version="2.0"> <channel> <title>SaveSpell :: Available domains</title> <link>http://www.domain.com/</link> <description>Expiring and expired word list domains</description> <language>en-us</language> <ttl>1</ttl> <item> <title>jyanen.com</title> <category></category> <pubDate>Wed, 24 Oct 2007 15:29:27 UTC</pubDate> <link>http://www.domain.com/info/jyanen.com</link> <description><![CDATA[<img src="http://www.domain.com/images/status/4.png" alt="" /> jyanen.com]]></description> </item> <item> <title>tertis.net</title> <category></category> <pubDate>Wed, 24 Oct 2007 08:17:32 UTC</pubDate> <link>http://www.domain.com/info/tertis.net</link> <description><![CDATA[<img src="http://www.domain.com/images/status/2.png" alt="" /> tertis.net]]></description> </item> <item> <title>poutek.com</title> <category></category> <pubDate>Wed, 24 Oct 2007 08:14:20 UTC</pubDate> <link>http://www.domain.com/info/poutek.com</link> <description><![CDATA[<img src="http://www.domain.com/images/status/2.png" alt="" /> poutek.com]]></description> </item> <item> <title>lmass.com</title> <category></category> <pubDate>Wed, 24 Oct 2007 07:40:30 UTC</pubDate> <link>http://www.domain.com/info/lmass.com</link> <description><![CDATA[<img src="http://www.domain.com/images/status/2.png" alt="" /> lmass.com]]></description> </item> </channel> </rss> Code (markup): Any help would be appreciated.
$xml = simplexml_load_file('file.xml'); foreach ($xml->xpath('channel/item') AS $item) { echo $item->title, "<br />\n"; } PHP:
i uploaded this to my PHP4 server and its unable to detect the function whats the equivalent of it in PHP4?
Do you maybe have an option to change between PHP 4 and PHP 5 in your control panel? (If not, you should ask your host to upgrade because the support for PHP 4 ends this year - Source) If you don't have any of these options, I'll code up something else.
My host doesn’t have PHP5, but I’ll tell them about the end of support. Its worth pointing their attention to that. But for the time being would it be OK with you to have a look at coding something up for me?
This should do it: $xml = file_get_contents('file.xml'); preg_match('~<channel>(.*?)</channel>~si', $xml, $channel); preg_match_all('~<item>(.*?)</item>~si', $channel[1], $items); foreach ($items[1] AS $item) { preg_match('~<title>(.*?)</title>~i', $item, $title); echo "<p>{$title[1]}</p>\n"; } PHP:
Hm, let's try it this way: $xml = file_get_contents('file.xml'); preg_match_all('~<title>(.*?)</title>~si', $xml, $titles); array_shift($titles[1]); foreach ($titles[1] AS $title) { echo "<p>{$title}</p>\n"; } PHP: Works for me too (tested).