...

View Full Version : Pulling Info From An RSS feed Using PHP? Help Needed Please.



LJackson
12-08-2008, 10:31 PM
Hi All,

I am growing increasingly fustrated with using php to pull out specific content from an RSS feed.

I have managed to get all the info out but for some reason when i try to pull out specific bit of information it wont do it it returns nothing?

here is the feed
feed (http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D)

and here is my code:

<?php require('_drawrating.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<link rel="stylesheet" type="text/css" href="css/rating.css" />

<title></title>
<style type="text/css">
<!--
a:link {
color: #0066FF;
}
a:visited {
color: #0066FF;
}
a:hover {
color: #0000FF;
}
a:active {
color: #0066FF;
}
-->
</style></head>

<?php

define("MAGPIE_INPUT_ENCODING", "UTF-8");
define("MAGPIE_OUTPUT_ENCODING", "UTF-8");
define("MAGPIE_CACHE_DIR", "./magpierss/cache");
define("MAGPIE_CACHE_ON", 1);
define("MAGPIE_CACHE_AGE", 3600);
include_once("./magpierss/rss_fetch.inc");

print "<body>";



$rss = fetch_rss("http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D");

$loop_count = 0;
for ($r = 0; $r <= $loop_count; $r++) {

foreach ($rss->items as $item){
if ($r <= $loop_count){
$href = $item['link'];
$title = $item['title'];
$desc = $item['description'];
$ref_date = $item['pubdate'];
$content = $item['atom_content'];

print "Full Content Of Feed Item";
//ORIGINAL
print "<div class='recommends'>";
print $content;
print "<br>";

//MINE
print "My Attempt";
print "<div class='recommends'>";
print "<a href=$href>$title</a>";//Linked Title

$r++;
print "</div>";
}
}
}
?>
</body>
</html>

and "test" page from the above code
page (http://www.kernow-connect.com/affiliate/entertainment(test3).php)

I am able to extract the title and the link but for some reason i cannot for the life of me get the image or the other info.

i want to reduce the size of the font and maybe get rid of some of the text so that it fits into the box

can anyone help me achieve this its doing my head in :)
do i need to decode the feed first or something?

i can provide some of the magpierss parser code if need be

Many Thanks
Luke

hinch
12-08-2008, 11:04 PM
isn't it just a case of doing

$cover= $item['coverArt'];

<img scr="$cover" />

I must admit to never having tried this though

mlseim
12-08-2008, 11:13 PM
Try the code below.

This the WHOLE code! No Magpie needed.


<?php
// rss page -
$feed_url = "http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D";

// Load XML.
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 5;

foreach ($xml->channel->item as $item) {
if($count > 0){
echo"
<div style='font-family:arial; font-size:.8em;'>
<b>{$item->title}</b><br />
{$item->description}<br />
<a href='{$item->link}'>view it</a>
<br /><br />
</div>
";
}
$count--;
}
?>


Some webhosts require PHP CURL method.
If yours requires the use of CURL, let me know.

EDIT:
I forgot the image ... I'll get that and repost.


.

hinch
12-08-2008, 11:29 PM
just looked up my only code ever where i've used RSS :)

basically its for grabbing the rss feed from those silly minicity sites and spitting out the latest happenings.

Now its not linked to your problem obviously but perhaps you could reverse it so to speak :)



echo "<span class='style1'><strong>Latest Happenings</strong></span>";
echo "<div align='left' class=\"style1\">";
$site = "http://".$cityname.".myminicity.com/rss";
$fp = @fopen($site,"r");
while(!feof($fp)) $raw .= @utf8_decode(fgets($fp, 4096));
fclose($fp);

if( eregi("<item>(.*)</item>", $raw, $rawitems ) ) {
$items = explode("<item>", $rawitems[0]);

for( $i = 0; $i < count($items)-1; $i++ ) {
eregi("<title>(.*)</title>",$items[$i+1], $title );
eregi("<url>(.*)</url>",$items[$i+1], $url );
eregi("<categorie>(.*)</categorie>",$items[$i+1], $cat);
echo "<li>".$title[1].$cat[1];
}

echo "</div>";}
unlink($file);

?>

LJackson
12-08-2008, 11:38 PM
isn't it just a case of doing

$cover= $item['coverArt'];

<img scr="$cover" />

I must admit to never having tried this though

Hi mateyeah i thought this also but for some odd reason it returns no value :(

LJackson
12-08-2008, 11:43 PM
Hi mlseim,

this looks promising :)
just need the picture and price and alls good :)

cheers
Luke

p.s my webhost doesnt support Curl :(

mlseim
12-08-2008, 11:50 PM
Example of grabbing their own HTML code ... or parsing it out yourself.

Because they have tags with colons "itms:coverArt" ... that refers to a "NameSpace URI",
and requires some extra coding. Not sure how you want to display stuff, but it can
be done several ways.

The code now ...


<?php
// rss page -
$feed_url = "http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D";

// Get XML
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 5;


foreach ($xml->channel->item as $item) {
if($count > 0){

// Grabbing the NameSpace URI for "itms" and "content" ...
$ns_itms = $item->children('http://phobos.apple.com/rss/1.0/modules/itms/');
$ns_content = $item->children('http://purl.org/rss/1.0/modules/content/');

echo"
DISPLAYING THE PROVIDED HTML CONTENT ...<br />
<div style='font-family:arial; font-size:.8em;'>
{$ns_content}<br /><br />

DISPLAYING THE INFO MANUALLY ...<br />
<img src='{$ns_itms->coverArt}' /><br />
{$item->content}<br />
<b>{$item->title}</b><br />
{$item->description}<br />
<a href='{$item->link}'>view it</a>
<br /><br />
<hr>
<br /><br />
</div>
";
}
$count--;
}
?>


A working example of my code:
http://www.cgrelayforlife.com/ipod.php

hinch
12-08-2008, 11:54 PM
ahh I've finally noticed why its not a simple case of pulling out the coverArt field :)

DOH

its because its <itms:coverArt> not just <coverArt> like the title/link/description

hrmp need to think about this then although my method above should work would just need to add in

eregi("<itms:coverArt(.*)</url>",$items[$i+1], $art);

echo $art;

LJackson
12-08-2008, 11:56 PM
WOW mlseim thats cool,

i knew there must be a way to do it lol just didnt know how,

im gonna have a play around with it to see if i can get a few more things out of the feed and add my own styling see how i get on,

i will more thank likley be calling on you again for some help if you dont mind :)

time to go and play around :)

thanks so much for this guys i really appreciate it
Luke

LJackson
12-09-2008, 12:02 AM
ahh I've finally noticed why its not a simple case of pulling out the coverArt field :)

DOH

its because its <itms:coverArt> not just <coverArt> like the title/link/description

hrmp need to think about this then although my method above should work would just need to add in

eregi("<itms:coverArt(.*)</url>",$items[$i+1], $art);

echo $art;

HI mate i inserted this code but didnt get any results, i replaced

<itms:coverArt(.*)</url> with
<itms:coverArt(.*)</itms:coverArt> and its displaying "array" instead of the pics?

any ideas cheers mate.

LJackson
12-09-2008, 12:34 AM
mlseim,

i have managed to get the genre but am unable to get the album and album price?

also i am trying to get the image the same size as in the original feed but when i do it the image is distorted is there a way to do this so that the quality stays the same?

here is how i resized the image size

<a href='{$item->link}'><img src='{$ns_itms->coverArt}' height = '100' width = '100' border='0' /></a><br />


cheers mate
Luke

mlseim
12-09-2008, 12:41 AM
They list the image 3 times, each one a different size.
We're pulling the first one (unfortunately the smallest size).

So, we'll have to do some fancy footwork to get the 3rd image.

I'll experiment and get back on this.

mlseim
12-09-2008, 01:02 AM
My test site for the code below:
http://www.cgrelayforlife.com/ipod.php
(I didn't use the right charset (content-type), so my money symbol is weird)

With a few tricks to alter the URL to the image ...


<?php
// rss page -
$feed_url = "http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D";

// Get XML
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 5;

foreach ($xml->channel->item as $item) {
if($count > 0){

// Grabbing the NameSpace URI for "itms" and "content" ...
$ns_itms = $item->children('http://phobos.apple.com/rss/1.0/modules/itms/');
$ns_content = $item->children('http://purl.org/rss/1.0/modules/content/');

// Trick the URL to grab the larger size image ...
$photo=str_replace("53x53-50","100x100-75",$ns_itms->coverArt);

echo"
<img src='$photo' /><br />
<b>{$ns_itms->album} - {$ns_itms->artist}</b><br />
{$ns_itms->albumPrice}<br />
<a href='{$item->link}'>view it</a><br />
{$item->category}
<br /><br />
<hr>
<br /><br />
</div>
";
}
$count--;
}
?>

LJackson
12-09-2008, 11:02 AM
OMG thats awsome thank you so much for doing this :D:D

will this method work for other rss feeds? is it a case of defining the child nodes and then the info?

also what about caching, is there a way to make the page load faster? as i think when testing the page speed it was around 60seconds on 54kbs connection

also mate what are you using to know what text to use to pull out the correct info like album price => albumPrice because im still using the magpierss parser text and the album price is all in small letters and wont work, so how are you finding out the correct text to use? :)

cheers mate
Luke

hinch
12-09-2008, 12:52 PM
he's effectively loading them as 2 seperate rss feeds one containing the itms: section contents and one containing the main feed

so $ns_itms->albumPrice is reading from the main feed (ns_itms) and pulling in the variable albumPrice from the sub feed and $item->category is pulling from the main feed

it looks like $ns_content = $item->children('http://purl.org/rss/1.0/modules/content/'); is unused so can probably be commented out

mlseim
12-09-2008, 12:58 PM
I was thinking that having these two lines within the loop might make it slower:

// Grabbing the NameSpace URI for "itms" and "content" ...
$ns_itms = $item->children('http://phobos.apple.com/rss/1.0/modules/itms/');
$ns_content = $item->children('http://purl.org/rss/1.0/modules/content/');

There is no way around it though (that I know of).
I guess you don't need the $ns_content line anymore ... I'm not grabbing
anything from that NameSpace. Try removing that line.

simplexml_load_file is designed to just grab whatever strings are between tags.
As with most PHP5 classes and functions, they've simplified many things.

LJackson
12-09-2008, 06:13 PM
Ok cheers mate :)

1 other thing can you get the total songs (for each of the items) out of the feed?

ive tried but had no success :( this is the last thing i need for this feed :)

many thanks
Luke

mlseim
12-09-2008, 07:06 PM
doh!

At the moment (at work), I'm behind a firewall that won't allow me
to view any MP3 or Video RSS feeds. If you can, tell me the tag
name that surrounds the total songs.

And I think you mean the number of songs on each album?

LJackson
12-09-2008, 07:11 PM
lol,

um i cant see a tag thats whats confusing me :(

yeah the total songs on each album

here is the code for a single item.

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/"><channel xmlns:cfi="http://www.microsoft.com/schemas/rss/core/2005/internal" cfi:lastdownloaderror="None"><title cf:type="text">iTunes Top 10 Songs</title><link>http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewTop% 3Fid%3D130%26popId%3D1%26partnerId%3D2003</link><description cf:type="text">iTunes Store: Today's Top 10 Songs</description><language>en</language><copyright cf:type="text">Copyright 2008 iTunes S. r.l.

</copyright><lastBuildDate>Tue, 09 Dec 2008 11:06:33 GMT</lastBuildDate><atom:updated>2008-12-09T11:06:33Z</atom:updated><generator>iTunes Music Store RSS v1.0.0</generator><webMaster>musicstore@apple.com</webMaster><ttl>240</ttl><dc:creator>iTunes Music Store</dc:creator><dc:date>Tue 09 Dec 2008 03:06:33 -800</dc:date><sy:updatePeriod>hourly</sy:updatePeriod><sy:updateFrequency>1</sy:updateFrequency><sy:updateBase>2003-09-01T12:00+00:00</sy:updateBase><image><url>http://ax.itunes.apple.com/images/rss/badge.gif</url><title>iTunes Music Store</title><link>http://www.apple.com/itunes/</link><width>88</width><height>31</height></image><item><title xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="text">10. All I Want for Christmas Is You - Mariah Carey</title><link>http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D295877271%26id%3D295877171%26s%3D143444%26partnerId%3D2003&amp;v0=9990</link><pubDate>Tue, 09 Dec 2008 11:06:33 GMT</pubDate><atom:published xmlns:atom="http://www.w3.org/2005/Atom">2008-12-09T11:06:33Z</atom:published><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2008-12-09T11:06:33Z</atom:updated><description xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="html">&lt;table border=0 width="100%"&gt;&lt;tr&gt;&lt;td&gt;&lt;table border=0 width="100%" cellspacing=0 cellpadding=0&gt;
&lt;tr valign=top align=left&gt;
&lt;td align=CENTER width=166 valign=TOP&gt;&lt;a href="http://clkuk.tradedoubler.com/click?p=23708&amp;amp;a=1515427&amp;amp;url=http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?id%3D295877171%26s%3D143444%26partnerId%3D2003&amp;amp;v0=9990"&gt;&lt;img border=0 src="http://a1.phobos.apple.com/us/r1000/024/Features/0a/b6/e2/dj.sjxykgax.100x100-75.jpg"&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td width=10&gt;&lt;img alt="" width=10 height=1 src="http://ax.itunes.apple.com/images/spacer.gif"&gt;&lt;/td&gt;
&lt;td width="95%"&gt;&lt;b&gt;&lt;a href="http://clkuk.tradedoubler.com/click?p=23708&amp;amp;a=1515427&amp;amp;url=http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?id%3D295877171%26s%3D143444%26partnerId%3D2003&amp;amp;v0=9990"&gt;Christmas Hits&lt;/a&gt;&lt;/b&gt;&lt;br&gt;
&lt;a href="http://clkuk.tradedoubler.com/click?p=23708&amp;amp;a=1515427&amp;amp;url=http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewArtist?id%3D91853%26partnerId%3D2003&amp;amp;v0=9990"&gt;Mariah Carey&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;font size=3 face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"&gt;&lt;b&gt;Release Date:&lt;/b&gt;
14 November 2008&lt;br&gt;
&lt;/font&gt;&lt;font size=3 face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"&gt;&lt;b&gt;Total Songs:&lt;/b&gt;
82&lt;/font&gt;&lt;br&gt;
&lt;font size=3 face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"&gt;&lt;b&gt;Genre:&lt;/b&gt;
&lt;a href="http://clkuk.tradedoubler.com/click?p=23708&amp;amp;a=1515427&amp;amp;url=http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewGenre?id%3D8%26partnerId%3D2003&amp;amp;v0=9990"&gt;Christmas&lt;/a&gt;&lt;/font&gt;&lt;br&gt;
&lt;font size=3 face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"&gt;&lt;b&gt;Album Price:&lt;/b&gt;
9.99&lt;/font&gt;&lt;br&gt;
&lt;font size=3 face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"&gt;&lt;b&gt;Copyright&lt;/b&gt;
This compilation (P) 2008 Sony BMG Music Entertainment (UK) Limited&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
</description><atom:summary xmlns:atom="http://www.w3.org/2005/Atom" type="html">All I Want for Christmas Is You by Mariah Carey from the album [?]
</atom:summary><category domain="http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewGenr e%3Fid%3D8%26partnerId%3D2003&amp;v0=9990">Christmas</category><itms:artist xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/">Mariah Carey</itms:artist><itms:artistLink xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/">http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewArti st%3Fid%3D91853%26partnerId%3D2003&amp;v0=9990</itms:artistLink><itms:album xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/">Christmas Hits</itms:album><itms:albumLink xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/">http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fid%3D295877171%26s%3D143444%26partnerId%3D2003&amp;v0=9990</itms:albumLink><itms:albumPrice xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/">9.99</itms:albumPrice><itms:coverArt xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/" height="53" width="53">http://a1.phobos.apple.com/us/r1000/024/Features/0a/b6/e2/dj.sjxykgax.53x53-50.jpg</itms:coverArt><itms:coverArt xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/" height="60" width="60">http://a1.phobos.apple.com/us/r1000/024/Features/0a/b6/e2/dj.sjxykgax.60x60-50.jpg</itms:coverArt><itms:coverArt xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/" height="100" width="100">http://a1.phobos.apple.com/us/r1000/024/Features/0a/b6/e2/dj.sjxykgax.100x100-75.jpg</itms:coverArt><itms:song xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/">All I Want for Christmas Is You</itms:song><itms:songLink xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/">http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D295877271%26id%3D295877171%26s%3D143444%26partnerId%3D2003&amp;v0=9990</itms:songLink><itms:rank xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/">10</itms:rank><itms:rights xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/">This compilation (P) 2008 Sony BMG Music Entertainment (UK) Limited</itms:rights><itms:releasedate xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/">14 November 2008</itms:releasedate><cfi:id>16</cfi:id><cfi:read>true</cfi:read><cfi:downloadurl>http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&amp;TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D151542 7%26url%3D</cfi:downloadurl><cfi:lastdownloadtime>2008-12-09T11:06:17.277Z</cfi:lastdownloadtime></item><item><title xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="text">1. Run - Leona Lewis</title><link>http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D295671640%26id%3D295671619%26s%3D143444%26partnerId%3D2003&amp;v0=9990</link><pubDate>Mon, 08 Dec 2008 22:00:46 GMT</pubDate><atom:published xmlns:atom="http://www.w3.org/2005/Atom">2008-12-08T22:00:46Z</atom:published><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2008-12-08T22:00:46Z</atom:updated><description xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="html">&lt;table border=0 width="100%"&gt;&lt;tr&gt;&lt;td&gt;&lt;table border=0 width="100%" cellspacing=0 cellpadding=0&gt;
&lt;tr valign=top align=left&gt;

hope this helps :)

p.s im going out for a couple of hours so wont beable to respond till later :)

cheers mate
Luke

mlseim
12-09-2008, 07:39 PM
Now I had to reach into my bag of tricks to find a function that
parses a string between two other strings. A lifesaver function for
those that need it.

Here's the code now:


<?php
// rss page -
$feed_url = "http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D";

// Get XML
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 5;

foreach ($xml->channel->item as $item) {
if($count > 0){

// Grabbing the NameSpace URI for "itms" and "content" ...
$ns_itms = $item->children('http://phobos.apple.com/rss/1.0/modules/itms/');
$ns_content = $item->children('http://purl.org/rss/1.0/modules/content/');

// Trick the URL to grab the larger size image ...
$photo=str_replace("53x53-50","100x100-75",$ns_itms->coverArt);

// Parse-out the number of songs on an album ...
$songs = get_string_between($ns_content, "<B>Total Songs:</B>","</font>");

echo"
<img src='$photo' /><br />
<b>{$ns_itms->album} - {$ns_itms->artist}</b><br />
{$ns_itms->albumPrice}<br />
<a href='{$item->link}'>view it</a><br />
Genre: {$item->category}<br />
Total Songs: $songs
<br /><br />
<hr>
<br /><br />
</div>
";
}
$count--;
}

// I reach into my bag of tricks and use this function that I
// found on the internet. Credit goes to: http://www.justin-cook.com
//
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

?>


Note: Now we need to use $ns_content ... so make sure that NameSpace is entered.

Here is the test page:
http://www.cgrelayforlife.com/ipod.php


.

LJackson
12-09-2008, 11:14 PM
Hi mate thank you very much wow i never thought any of this was possible until today :)

many thanks for everything
Luke

LJackson
12-11-2008, 03:52 PM
Hi Mlseim,

I need your bag of tricks again :D

i am working on another feed and i have tried using what i have learnt from yourself but im not getting anywhere fast :(

i think the problem is because its an atom rss feed (would that make any difference?) I have managed to get the title and the link which was easy but after that i got nowhere, i tried using the get_string_between function to pull out the image info but apart from taking a fare while to load it didnt find anything.

here is the code for this (http://www.kernow-connect.com/affiliate/test.php)test page:


<?php

function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

$feed_url = "http://www.amazon.co.uk/rss/bestsellers/videogames?tag=AssocID-21";

// Get XML
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 1;

foreach ($xml->channel->item as $item) {
// Grabbing the NameSpace URI for "itms" and "content" ...
$ns_itms = $item->children('http://www.microsoft.com/schemas/rss/core/2005/');
$ns_content = $item->children('http://purl.org/rss/1.0/modules/content/');

// Trick the URL to grab the larger size image ...
$photo=str_replace("53x53-50","100x100-75",$ns_itms->coverArt);

// Parse-out the number of songs on an album ...
$image = get_string_between($ns_itms, 'tag=AssocID-21;','border=0');

if($count > 0){




echo"
<div class='recommends'>
<a href='{$item->link}'>{$item->title}</a><br />
<a href='{$item->link}'><img src='$photo' alt='{$ns_itms->artist} - {$ns_itms->album}' border='0' hspace='5' vspace='10'/></a>

";

}
$count--;
}
?>

i will keep on plugging away but if you can steer me in the correct direction i'd really appreciate it :)

many thanks
Luke

mlseim
12-11-2008, 04:27 PM
That feed has no "children" ...

The photo is simply contained within $item->description

My working test page:
http://www.cgrelayforlife.com/amazon.php



<?php

function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

$feed_url = "http://www.amazon.co.uk/rss/bestsellers/videogames?tag=AssocID-21";

// Get XML
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 3;

foreach ($xml->channel->item as $item) {

// Parse-out the photo for each item ...
$photo = get_string_between($item->description, 'AssocID-21">','</a>');

// Parse-out the cost for each item ...
$cost = get_string_between($item->description, '<strike>','</strike>');

// If you don't want the # of the item to appear,
// Use a modified title ... $short_title
list ($no, $short_title) = split (':', $item->title);


if($count > 0){
echo"
<div class='recommends'>
<a href='{$item->link}'>$photo</a><br />
<a href='{$item->link}'>{$item->title}</a><br />
COST: $cost<br />
<br />
Example of short title<br />
<b>$short_title</b>
<br /><br /><br />
";

}
$count--;
}
?>

LJackson
12-11-2008, 04:36 PM
:D:D:D

your a life saver mate,

should i use the get_string_between function to get other information out like platform for example because there are no nodes so to speak.

cheers mate
Luke

mlseim
12-11-2008, 04:39 PM
You'll see I added "cost" to my script above.

Platform will be easy too, because they only use <b> ... </b> for the platform:

// Parse-out the platform for each item ...
$platform = get_string_between($item->description, '<b>','</b>');

====================

FOR OTHERS THAT ARE FOLLOWING THIS LONG THREAD OF POSTS ...

I'm thinking that there are other ways to do this XML parsing.
I just use the methods shown because I think it's easiest.

If anyone has a more efficient way, please pipe-in.
I'm not really an expert about this, by any means.

But if anyone finds these methods interesting or a good alternative
to Magpie or other parsers, let me know. I hope this thread is proving
to be good information ... and I'm not doing it inefficiently.


.

hinch
12-11-2008, 04:45 PM
i'm following it as its rather interesting I've also tried writing a couple of generic parsers where you can pull any xml feed in an admin panel style setup then it lists the elements you want to display and you simply select them but i'm going no where fast with them so meh.

it seems handling xml and rss feeds in php whilst common is no easy task annoying thing is using c# its about 4 lines of code :(

mlseim
12-11-2008, 04:56 PM
Well ... C/C++ and Perl are on a totally higher plane than PHP ...

I think the problem (as I've seen it), is that XML feeds have become more
complicated than the earlier feeds. With the addition of "children", things
sort of fell apart. Someday, with PHP6 ?

And no matter how the XML classes are made, the feed authors stick information
into their own <![CDATA[ .... ]]> There's almost no way to cover all combination
of HTML tags. Parsing becomes a pain no matter what functions you use.

But the idea behind RSS Feeds is genius. XML at least provides some structure
that HTML cannot provide. There's at least a ray of hope that a person can get
some information without scraping web pages.

hinch
12-11-2008, 04:59 PM
i suspect it would be less of a problem if the feed creators stuck strictly to the rss and xml specifications instead of being twats and extending them tbh.

what would really make me a happy panda would be to remove rss feeds and instead they expose their "rss" via a proper web service. that way we could consume it properly.

I know soap is a pain in php :) but still better than manually writing a parser for every different feed around there.

mlseim
12-11-2008, 05:11 PM
Like an API (Application Program Interface) ...

If a site like amazon could provide a means of accessing their database
by using an API. Or maybe a database that keeps track of sports (game scores), etc.

Can you imagine the possibilities?
Even they charged a "token" yearly fee for access, it would open-up so
many new avenues for gathering and displaying information ... mind boggling.

The bottom line is money ... money from advertisers that base their costs on
how many people visit a website. If someone were to allow access to their
databases, people would not have to visit their site any more.

RSS sort of falls in-between ...

A site owner can provide "some" information, under their control, and cached
when and where they choose. The RSS feed user should link back, but they
technically don't have to. It still becomes a win-win situation for both parties,
but in the end, the database owner wins ... they control what is fed.

An interesting topic though ...
any others have thoughts on this?

LJackson
12-11-2008, 06:14 PM
You'll see I added "cost" to my script above.

Platform will be easy too, because they only use <b> ... </b> for the platform:

// Parse-out the platform for each item ...
$platform = get_string_between($item->description, '<b>','</b>');

====================



Cheers Mate !!!

hinch
12-11-2008, 06:41 PM
Like an API (Application Program Interface) ...

If a site like amazon could provide a means of accessing their database
by using an API. Or maybe a database that keeps track of sports (game scores), etc.

Can you imagine the possibilities?
Even they charged a "token" yearly fee for access, it would open-up so
many new avenues for gathering and displaying information ... mind boggling.

The bottom line is money ... money from advertisers that base their costs on
how many people visit a website. If someone were to allow access to their
databases, people would not have to visit their site any more.

RSS sort of falls in-between ...

A site owner can provide "some" information, under their control, and cached
when and where they choose. The RSS feed user should link back, but they
technically don't have to. It still becomes a win-win situation for both parties,
but in the end, the database owner wins ... they control what is fed.

An interesting topic though ...
any others have thoughts on this?


alot of people do this though via web services for example one of my sites pulls real time market feeds from reuters they're exposed via a web service (pure xml) which I then consume via c# in a .NET application. because its a web service though I can query back to the service and for example request only a list of stocks trading on AIM or only stocks with certain % gains/losses over a set time period. Basically I can treat the webservice as a remote database of sorts.

mlseim
12-11-2008, 07:43 PM
What does a service like that typically charge for access to the real-time database?

LJackson
12-11-2008, 07:51 PM
OK mate i have 1 small request

i am trying to get the:
Buy new: 39.99 34.29

ive tried many different combos but hopefully you may beable to help.

this is the codes i have narrowed it down to


&gt; &lt;br&gt;&lt;br&gt;&lt;a href="http://www.amazon.co.uk/Rayman-Raving-Rabbids-Party-Compatible/dp/B001C5FOS0/ref=pd_zg_rss_ts_vg_h__video-games_10?ie=UTF8&amp;amp;tag=AssocID-21"&gt;Buy new:&lt;/a&gt; &lt;strike&gt;39.99&lt;/strike&gt; &lt;font color="#990000"&gt;&lt;b&gt;19.56&lt;/b&gt;&lt;/font&gt;

ive used the </font> as the end tag but i cant get a start tag that gives me just what i want without bits of info before :)

$buynew = get_string_between($item->description, 'stars','</font>');

which displays this:
-4-5._V46891814_.gif" width="64" height="12" border="0" />
Buy new: 134.34

but i cannot get it so that first line buggers off :)

cheers mate
Luke

hinch
12-11-2008, 07:59 PM
$buynew = get_string_between($item->description, 'Buy new:','</font>');

echo "Buy new:".$buynew;

?

@mlseim don't know the access was provided by the client all I did was write the software to read the service.

http://about.reuters.com/productinfo/enterprise/?seg=10

LJackson
12-11-2008, 08:03 PM
[QUOTE=hinch;759033]
$buynew = get_string_between($item->description, 'Buy new:','</font>');

echo "Buy new:".$buynew;

?
QUOTE]

unfortunatly not as i require the link before that also :(

cheers mate
Luke

mlseim
12-11-2008, 08:32 PM
I see now what you're saying ...

There can be a crossed-out price, a sale price, and
another buy used price. So, there could be 3 prices.

Which price is the one you want?

And now I'm wondering why you just don't display
the whole thing with one echo ...

echo $item->description;

That pretty much has everything all put together for you.

LJackson
12-11-2008, 08:50 PM
Ok i have managed to get the used price but cannot get the buy new prices (crossed out and current price)

yeah the reason why i dont want to echo out all the item info with one echo is because i want to add my own style to it and display the info in hopefully a better way :)


cheers

mlseim
12-12-2008, 02:20 PM
Here's the whole thing broken down into components ...



<?php

function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

$feed_url = "http://www.amazon.co.uk/rss/bestsellers/videogames?tag=AssocID-21";

// Get XML
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 3;

foreach ($xml->channel->item as $item) {

// Parse-out the photo for each item ...
$photo = get_string_between($item->description, 'AssocID-21">','</a>');

// Parse-out the cost for each item (buy new and crossed-out prices) ...
$costs = get_string_between($item->description, 'Buy new:</a>','</font>');

$old_price = get_string_between($costs, '<strike>','</strike>');
$buynew_price = get_string_between($costs, '<b>','</b>');
$used_price = get_string_between($item->description, '<span class="price">','</span>');
$quantity = get_string_between($item->description, 'all">','</a>');

// If you don't want the # of the item to appear,
// Use a modified title ... $short_title
list ($no, $short_title) = split (':', $item->title);


if($count > 0){
echo"
<div class='recommends'>
<a href='{$item->link}'>$photo</a><br />
Original Title: <a href='{$item->link}'>{$item->title}</a><br />
Shortened Title: $short_title<br />
old price: $old_price<br />
buy new price: $buynew_price<br />
used price: $used_price<br />
quantity: $quantity<br />
<br />
<hr>
<br /><br />
";

}
$count--;
}
?>

LJackson
12-12-2008, 03:42 PM
nice one mate, i have managed to resize the image so that it is 100x100 i had to break it down into two sections the link and the image source

here is the code:

// Parse-out the photo for each item ...
$photolink = get_string_between($item->description, 'href="','<img src="');
$photosource = get_string_between($item->description, '<img src="','"');

<a href='$photolink'><img src='$photosource' alt='$short_title' width='100' height='100' border='0' vspace='10'/></a><br>


what is really anoying at the moment is trying to get just the customer rating image this is what ive got at the moment


$reviewsource = get_string_between($item->description, 'Customer Review:','width');


which is getting the rating info but there is something within the original code which is ending my div so all my items are inside of each other :(

this is the code that is got from my $reviewsource = get_string_between($item->description, 'Customer Review:','width');


&lt;img src="http://g-ecx.images-amazon.com/images/G/02/detail/stars-4-5._V46891814_.gif"

and i think its the "&lt;" which is causing it. what is "&lt;" and how do i remove it :) ive tried using:

$reviewsource = get_string_between($item->description, 'Customer Review:','&lt; ');

but have had no luck

here (http://www.kernow-connect.com/affiliate/test.php)is my test page to show you what i mean

and here is my code:

<?php

function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

$feed_url = "http://www.amazon.co.uk/rss/bestsellers/videogames?tag=AssocID-21";

// Get XML
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 10;

foreach ($xml->channel->item as $item) {

// Parse-out the photo for each item ...
$photolink = get_string_between($item->description, 'href="','<img src="');
$photosource = get_string_between($item->description, '<img src="','"');

// Parse-out the platform for each item ...
$platform = get_string_between($item->description, 'Platform:','Average');
$reviewsource = get_string_between($item->description, 'Customer Review:','width');
$buynew = get_string_between($item->description, '"#990000">','</b>');
$newlink = get_string_between($item->description, 'br','#990000');
$part1 = get_string_between($item->description, 'float:left;">','</div>');
$part2 = get_string_between($item->description, '</div>','(Ranking');

$costs = get_string_between($item->description, 'Buy new:</a>','</font>');

$old_price = get_string_between($costs, '<strike>','</strike>');
$buynew_price = get_string_between($costs, '<b>','</b>');
$used_price = get_string_between($item->description, '<span class="price">','</span>');
$quantity = get_string_between($item->description, 'all">','</a>');


list ($no, $short_title) = split (': ', $item->title);


if($count > 0){

echo"
<div class='recommendstest'>
$short_title<br>
<a href='$photolink'><img src='$photosource' alt='$short_title' width='100' height='100' border='0' vspace='10'/></a><br>
<b>Platform: </b>$platform
<b>Average Customer Review: </b><br>$reviewsource
</div>


";

}
$count--;
}
?>

cheers for your much needed continued help :)

hinch
12-12-2008, 03:51 PM
&lt; is the html code for <

$reviewsource = str_replace("$lt;","<",$reviewsource);

will replace it with its proper < as its the html tag opening don't forget to add a > at the end though to close the image tag properly

LJackson
12-12-2008, 04:00 PM
cheers hinch got it working now had to make a small change here and there lol

changed

$reviewsource = get_string_between($item->description, 'Customer Review:','width');

to

$reviewsource = get_string_between($item->description, 'Customer Review: <','width');


changed

<b>Average Customer Review: </b><br>$reviewsource

to

<b>Average Customer Review: </b><br><$reviewsource>

and all seems to be working.

why would a ">" cause my div to close?

note to self: must remember that &lt = > :D

hinch
12-12-2008, 04:41 PM
&lt; = <
&gt; = >

lt = less than
gt = greater than

:)
they didn't cause it to close what happened was you opened a tag with a < but never closed it so you ended up with < </div> somewhere along the line which ofc broke your layout :)

LJackson
12-12-2008, 05:35 PM
&lt; = <
&gt; = >

lt = less than
gt = greater than

:)


makes sense now lol

thanks for clearing that up for me :)

many thanks
Luke

LJackson
12-12-2008, 06:43 PM
you'll be glad to know that i've only got 1 more thing to do with this feed and im finished :)

and that is get the used and new items link

then im done :)

here (http://www.kernow-connect.com/affiliate/test.php)is the test page now

mlseim
12-12-2008, 08:16 PM
I only tested on a few items.
You might have to do some "if" statements to skip printing if a variable is not found or does not exist.



<?php

function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

$feed_url = "http://www.amazon.co.uk/rss/bestsellers/videogames?tag=AssocID-21";

// Get XML
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 3;

foreach ($xml->channel->item as $item) {

// Parse-out the photo for each item ...
$photo = get_string_between($item->description, 'AssocID-21">','</a>');

// Parse-out the cost for each item (buy new and crossed-out prices) ...
$costs = get_string_between($item->description, 'Buy new:</a>','</font>');

$old_price = get_string_between($costs, '<strike>','</strike>');
$buynew_price = get_string_between($costs, '<b>','</b>');
$used_price = get_string_between($item->description, '<span class="price">','</span>');
$quantity = get_string_between($item->description, 'all">','</a>');

$new_link = get_string_between($item->description, '<br /><br /><a href="','">Buy');
$used_temp =get_string_between($item->description, '</font> <br /><a href="','used & new');
list ($used_link, $no) = split ('\"', $used_temp);


// If you don't want the # of the item to appear,
// Use a modified title ... $short_title
list ($no, $short_title) = split (':', $item->title);


if($count > 0){
echo"
<div class='recommends'>
<a href='{$item->link}'>$photo</a><br />
Original Title: <a href='{$item->link}'>{$item->title}</a><br />
Shortened Title: $short_title<br />
old price: $old_price<br />
buy new price: $buynew_price<br />
used price: $used_price<br />
quantity: $quantity<br />
<br />
<a href='{$new_link}'>buy new</a><br />
<a href='{$used_link}'>buy used</a>
<hr>
<br /><br />
";

}
$count--;
}
?>

LJackson
12-12-2008, 10:04 PM
cheers mate im running out of appreciative words to say :D

thank you!!!!!!!

its seems to work for all of the 10 items :)

cheers
Luke

LJackson
12-12-2008, 10:46 PM
ok i hit a little snag,

on my local host everything work really well,

once i have uploaded it to my webspace its a bit tempermental

at the moment the buy # used and new link doesnt want to play :(

is there something i need to enable somewhere? seems odd that that is the only one not to work

here is the site (http://www.kernow-connect.com/affiliate/entertainment.php)

any ideas
cheers
Luke

mlseim
12-13-2008, 01:37 AM
I'm looking at this line on your web page:

<div class='feeditems_prices'><a href='http://www.amazon.co.uk/gp/offer-listing/B000XJNTNS/ref=pd_zg_rss_ts_vg_h__video-games_1'></b></a> From £29.99</div></div>

The </b></a> is in the wrong place.

But the link itself looks OK.

I guess I'll need to see your actual script again.

====
We're going to make this the longest thread in CodingForums history :)

hinch
12-13-2008, 12:00 PM
its a tough subject though and I doubt anyone has ever really gone into RSS feeds and manual transforms in such detail on here :)

LJackson
12-13-2008, 12:37 PM
Hi Guys,

ok i have changed the <b></a> around and it has made no difference :( lol

here is my code:


$feed_url = "http://www.amazon.co.uk/rss/bestsellers/videogames?tag=AssocID-21";

// Get XML
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 1;

foreach ($xml->channel->item as $item) {

// Parse-out the photo for each item ...
$photolink = get_string_between($item->description, 'href="','<img src="');
$photosource = get_string_between($item->description, '<img src="','"');

// Parse-out the platform for each item ...
$platform = get_string_between($item->description, 'Platform:','Average');
$reviewsource = get_string_between($item->description, 'Customer Review: <','width');
$buynew = get_string_between($item->description, '"#990000">','</b>');
$newlink = get_string_between($item->description, 'br','#990000');
$buynewlink = get_string_between($item->description, '<a href="','">');
$buyusedlink = get_string_between($item->description, '<a href="','condition=all');

$used_temp =get_string_between($item->description, '</font> <br /><a href="','used & new');
list ($used_link, $no) = split ('\"', $used_temp);


// If you don't want the # of the item to appear,
// Use a modified title ... $short_title
list ($no, $short_title) = split (':', $item->title);

$costs = get_string_between($item->description, 'Buy new:</a>','</font>');
$old_price = get_string_between($costs, '<strike>','</strike>');
$buynew_price = get_string_between($costs, '<b>','</b>');
$used_price = get_string_between($item->description, '<span class="price">','</span>');
$quantity = get_string_between($item->description, 'all">','</a>');


list ($no, $short_title) = split (': ', $item->title);


if($count > 0){


echo"
<a href='{$item->link}'>$short_title</a><br>
<a href='$photolink'><img src='$photosource' alt='$short_title' width='100' height='100' border='0' vspace='10'/></a><br>

<div class='feedcontainer_yellow'>
<div class='feeditems_platform_review'><b>Platform</b><br>$platform</div>
<div class='feeditems_platform_review'><b>Average Review</b><br><$reviewsource></div></div>

<div class='feedcontainer_pink'>
<div class='feeditems_prices'><b><a href='$buynewlink'>Buy New</b></a><br />$buynew_price</div>
<div class='feeditems_prices'><b>Was</b><br /><s>$old_price</s></div>
<div class='feeditems_prices'><b><a href='$used_link'>$quantity</a></b> From $used_price</div></div>


";

}
$count--;
}



it seems strange that it works on my local host but not once its uploaded.

cheers

LJackson
12-13-2008, 12:40 PM
its a tough subject though and I doubt anyone has ever really gone into RSS feeds and manual transforms in such detail on here :)

your right there mate, it is very tough, im just glad that ive got two people who know alot more than me and are "happy" to help :)

hopefully this thread will help others understand rss in great detail i know its helped me a great deal.

LJackson
12-13-2008, 12:43 PM
====
We're going to make this the longest thread in CodingForums history :)

lol all my threads seem to be long and complicated i think i'll be banned soon :D

p.s the link is fine its just the value of $quantity that seems to be lost :)

hinch
12-13-2008, 01:39 PM
i wouldn't call me an expert php to me is a hobby language I do for fun think I learnt enough to make an e-commerce site in about 4 hours but there's so much more I just don't know about the language yet.

As for your problem don't suppose yoru developing on windows and hosting on linux? could it be a case sensitivity issue ? (really going on a limb here as I'm not sure what else could be wrong)

LJackson
12-13-2008, 05:36 PM
nah both are on windows

LJackson
12-13-2008, 09:26 PM
ok so at the moment i have inserted text custom text where the number of items should be

like so

<div class='feeditems_prices'><b>Used and New</b><br />
$used_price</div>


which looks ok :)

i have another small problem, using another feed from amazon on future releases i thought all i would need to do is change the feed url and bobs your uncle but because these are future releases not all of the items have a customer rating or old price so i need to use an if statment to see if they exist.

would this be the best way around this? because at the moment because some of the info is missing its messing up my styling :(

here (http://www.kernow-connect.com/affiliate/stores.php?sID=Amazon)

under the new releases tab

EDIT
===

Ok i have solved the styling problem, it was caused by trying to recieve the platform using:

$platform = get_string_between($item->description, 'Platform:','Average');


which i have replaced with:

$platform = get_string_between($item->title, '(',')');


because the platform is included within each title so i just nicked it from there, and therefor solved my style problem :)

i would still like to know how to check if a string/expression exists?

EDIT2
====

Ok i have used an if statment to check if the value of $reviewsource = get_string_between($item->description, 'Customer Review:','<br />'); is not equal to nothing

if ($reviewsource <> "") {
$review = $reviewsource;
}
else
{
$review = "No customer reviews yet";
}


which works :D

no outstanding problems as yet :D


cheers
Luke

hinch
12-14-2008, 12:24 AM
assuming your $reviewsource var contains just something like "amazon" and you don't have to do anything fancy with it apart from just echo it out at some point you have 2 real ways of doing it i guess though there could be 3


if (strlen($reviewsource)>=1) {
$review = $reviewsource;
} else {
$review = "No customer reviews yet";
}

This is how i typically do it.

you could also do


if (isset($reviewsource)) {
$review = $reviewsource;
} else {
$review = "No customer reviews yet";
}

Though this will break if you don't clear out $review source at the end of each loop before you start the next iteration.

or going on a limb you could do this i suppose (don't think this would be recommended though)


if ($reviewsource != "") {
$review = $reviewsource;
} else {
$review = "No customer reviews yet";
}

LJackson
12-14-2008, 12:59 PM
$reviewsource var contains an image source tag and url for the rating image :)

just out of curiosity why don't you think this would be recommended?


if ($reviewsource != "") {
$review = $reviewsource;
} else {
$review = "No customer reviews yet";
}

as thats what im using at the mo and its working, but if the others are better i'd prefere to use one of them :)

cheers
Luke

hinch
12-14-2008, 01:03 PM
I seem to remember its something to do with being NULL and "" are different things.

Can't remember where I read it though was somewhere on here :)

LJackson
12-14-2008, 01:07 PM
ah right should i use:

if (strlen($reviewsource)>=1) {
$review = $reviewsource;
} else {
$review = "No customer reviews yet";
}

instead then?

cheers
Luke

hinch
12-14-2008, 01:12 PM
thats the way I personally do it that way I'm ensuring the variable has at least some content in it (wether its the right content or not who knows :) )

But at the end of the day its upto you every coder has their own way of doing things and in php it seems even more so than other languages as there's so many ways of doing different things where in other languages there's often only 1 or 2 ways of doing something

LJackson
12-14-2008, 01:17 PM
ok cool, i think i will go with your suggestion, it will be learning a new way of doing it, and im sure it will be useful to know. :)

mlseim
12-14-2008, 05:45 PM
Hinch,

A good example of what you're talking about (null vs isset) is within the
explanation of isset() vs empty();

Isset() checks if a variable has a value including ( False , 0 , or Empty string) ,
But not NULL. It will Return TRUE if variable exists; otherwise FALSE.

The empty() function checks if the variable has an empty value, empty string , 0, NULL ,or False. It Returns FALSE if the variable has a non-empty and non-zero value.

<?php
$var = 0;

// Evaluates to true because $var is empty
if (empty($var)) {
echo '$var is either 0, empty, or not set at all';
}

// Evaluates as true because $var is set
if (isset($var)) {
echo '$var is set even though it is empty';
}
?>

This is the problem with using "" ...

The following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)

So, the main determination would be whether your are using strings or integers.

hinch
12-14-2008, 07:07 PM
knew i'd read about it somewhere couldn't remember where though :)

anyway as i said thats why i use strlen() and just make sure that if a field is supposed to be null/empty/whatever that its length is less than 1 :)

too many ways of doing things in php i get confused but like i mentioned a few posts back i'm still a php beginner in the scheme of things

LJackson
12-14-2008, 08:03 PM
ok guys this should be easy for you,

new feed this time a product feed :) (trying to keep you on your toes lol)

its very easy to extract the info from it which i have done :)
but the release date is stored like 12/05/08 00:00:00

the time is always 00:00:00 so i dont want to display that,

i thought about using the get_string_between but for some reason this wont work not sure if my starting string is correct

$date = get_string_between($item->fields->Release_Date, '>','00:00:00');


but i get nothing :(

here (http://www.kernow-connect.com/affiliate/feeds/hmvtop10.xml)is the feed

also maybe slightly harder, how do i sort the feed by release date so that the most recent items are first?

here is my code so far

<?php
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

$feed_url = "http://www.kernow-connect.com/affiliate/feeds/hmvtop10.xml";

// Get XML
$xml=simplexml_load_file($feed_url);

// How many items to display from the RSS Feed ...
$count = 10;

foreach ($xml->product as $item) {

if ($item->shippingCost == '0'){//shipping is always 0 as hmv offer free delivery
$shipping = "Free";
}
else {
$shipping = "{$item->shippingCost}";
}


if($count > 0){

echo"

<div class='top10container'>
<div class='top10title'><a href='{$item->deepLink}'>{$item->productname}</a><br></div><br />
<div class='top10picture'><a href='{$item->deepLink}'><img src='{$item->imageURL}' alt='{$item->productname}' height='100' border='0'/></a><br></div>

<div class='storesfeedcontainer_yellow'>
<div class='feeditems_platform_review'><b>Name</b><br>{$item->productname}</div>
<div class='feeditems_platform_review'><b>Availability</b><br>{$item->availability}</div>
</div>

<div class='storesfeedcontainer_pink'>

<div class='feeditems_prices'><b>Price</b><br />
{$item->Price}</div>
<div class='feeditems_prices'><b>Shipping Costs</b><br />
$shipping</div>
<div class='feeditems_prices'><b>Release Date</b><br />
$date</div>

</div></div>


";

}
$count--;
}
?>


cheers

hinch
12-14-2008, 09:12 PM
you don't sort it without storing it all somewhere into a big array or perhaps a db table to then sort on it as you can't sort directly on an rss feed unless ofc you wanna mess around with transformations which i think are massively out of scope for this.

as for removing 00:00:00 get your entire date thing

$var = explode(" ","12/05/08 00:00:00");
echo $var[0];

since its always the same that should work just splitting it down into mini array :) you could also use rtrim() http://uk3.php.net/rtrim

LJackson
12-14-2008, 09:35 PM
hi mate,

i understand about the sorting, i was'nt a big concern of mine anyways but would have been a nice touch :)

as for the date i think i have confused you? the date/time is pulled out using {$item->fields->Release_Date} which returns a date and time in the format 00:00:0000 00:00:00 its only the time that stays the same the date changes

so im not sure if the above solution will work or not, or am i being thick? :)

i will look at rtrim see what thats all about :)

cheers
Luke

hinch
12-14-2008, 09:43 PM
your being thick :)

your date is always in the high format
<date><space><time> as returned by $item->fields->Release_Date

so using my code above


$var = explode(" ",$item->fields->Release_Date);
echo $var[0];

This will split your Release_Date into 2 parts on the space so you'll have an array $var with the values "<date>,<time>" since you only want the first element of the array <date> you simply echo out array column zero $var[0]

:)

rtrim will do exactly the same except saves you having to use arrays

rtrim($item->fields->Release_Date," 00:00:00")

LJackson
12-14-2008, 09:59 PM
hay theres nothing wrong with being thick once in a while :D

got it working thankyou!!

hinch
12-14-2008, 10:00 PM
which method did you use in the end?

don't worry about being thick i do it ALL the time :)

LJackson
12-14-2008, 10:18 PM
lol :D

i used the rtrim method looked tidier and simpler to understand if i look back at it :)

LJackson
12-18-2008, 04:10 PM
Hi Guys,

need a bit of help, like on the last feed where you provided me with the method of cutting the 1#: from the title to give me a shorter title, i want to do that with the first feed but for some reason i am unable to do it

here is the code you provided

list ($no, $short_title) = split (': ', $item->title);

and here is what i did to try and do the same for the other feed

list ($no, $short_title) = split ('.', $item->title);


which isnt returning anything
the title is for example 1. Hallelujah - Alexandra Burke and i want it to be just Hallelujah - Alexandra Burke

how would i do this :)

p.s here is the link to the rss feed if you need it
itunes (http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D)

many thanks
Luke

mlseim
12-18-2008, 05:25 PM
I think a period is a special character that needs to be escaped:

list ($no, $short_title) = split ('\.', $item->title);

hinch
12-18-2008, 05:41 PM
personally i'd split on space and then recombine the string in the order I wanted rather than just split off the fullstop. though i do like making life hard for myself too

LJackson
12-18-2008, 06:05 PM
I think a period is a special character that needs to be escaped:

list ($no, $short_title) = split ('\.', $item->title);

cheers mate thats working :D


personally i'd split on space and then recombine the string in the order I wanted rather than just split off the fullstop. though i do like making life hard for myself too

lol as do i mate

LJackson
12-18-2008, 06:29 PM
another one for you :)

i have split a title twice so that i have

list ($short_title, $license) = split ('-', $item->productname);
list ($no_of_months, $spare) = split (' ', $license);

1st line splits panda anti virus 2009 - 12 month license into
panda anti virus 2009 and 12 month license

2nd line is supposed to split 12 month license into 12 and month license but its not. i just want the number but because there are no "special" characters just spaces i thought the above would work, i tried a / before and after but that didnt work, any ideas

cheers

LJackson
12-18-2008, 06:48 PM
ok ive simplified it and got it working using:

$months = rtrim($license," Month License");

and its working. :)

just out of curiosity(as it may come up with a feed) if the title had just spaces and is different for each item e.g

this is a title for item 1

how would i get "is a title" out of it

just relised that using the above method would work :) answered my own question, is that the best way to use rtrim?

cheers

mlseim
12-18-2008, 08:09 PM
And for future knowledge ....

know that the escape is \ instead of /

Example: '\.'

LJackson
12-18-2008, 08:14 PM
oops ok i will make a mental note of that :D

cheers

LJackson
01-02-2009, 03:50 PM
Hi Guys, Happy New Year :)

i have another problem :(

here is my rss feed:
http://www.amazon.co.uk/rss/bestsellers/videogames?tag=kernconn-21

and i am trying to get the product/item link but with the
?ie=UTF8&tag=kernconn-21 at the end of it as it is in the source file, it seems to work ok in my local browser but after i upload it when i hover over the title in the status bar at the bottom of the browser it just has the basic link without the extention??? now sure why tho.

it seems to be affecting my tracking figures. as they are not being registered :(

any ideas

ive tried:

$link = "{$item->link}"."?ie=UTF8&tag=kernconn-21";

but in the satatus bar it adds about 6 spaces inbetween the link and the extra info?

cheers
Luke

hinch
01-02-2009, 04:09 PM
you can use trim() to remove the additional spaces
eg:

$firstpart.trim($link);

LJackson
01-02-2009, 05:01 PM
thanks mate its now displaying in the status bar correctly, hopefully it tracks it properly... we'll see :)

cheers

John37309
01-03-2009, 04:20 AM
Luke,
This is an interesting thread. I have read a good bit of what you have been trying to do with your rss feeds, and i see you are using magpierss to parse your feeds.

I have been working in another thread trying to solve some caching issues that i am having with my rss feed parser; http://www.codingforums.com/showthread.php?t=155099

I have been using simplepie to parse my feeds; http://simplepie.org/ and i have found it very usefull. It could well resolve some of the problems you have been having. If you have time, try our simplepie. They have a good demo for trying it; http://simplepie.org/demo/

John.

LJackson
01-04-2009, 02:05 PM
Hi John,

hope you have found this thread as intersting as i have :)
i spent hours trying different parsers to help me display the feeds as i wanted and was starting to give up on the idea until mlseim and hinch came along and worked their magic, and i am able to pull out specific bits of the rss/product feeds and display as i want them.

i am doing this without the use of magpierss or any other parser, but instead i am using the built in php function

$xml=simplexml_load_file("feedURL");
which works great!!!

i tried simplepie a while back but because i didnt have the knowledge to use it i gave up on it.

i will have a look though your thread to see what your are trying to achieve :)

best of luck
Luke

edit
----

Just been and had a look through your thread and it looks to me Fou-Lu is doing really well with it and because he has been helping from the begining he has a good understanding of where your going with it and how to progress. for me personally i would find it hard to jump in and pick up whats been done and how to move on so im not much good to you im afraid :( because we have both gone down seperate paths with displaying the feeds i dont want to throw in some which may potentially do more damage than good :)

i wish you all the best and hope you achieve what you are trying to achieve :)
all the best
Luke

John37309
01-04-2009, 03:07 PM
There is your feed passed through the Simplepie demo; iTunes apple music feed (http://simplepie.org/demo/?feed=http%3A%2F%2Fax.itunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwpa%2FMRSS%2Ftopsongs%2Fsf%3D143 444%2Flimit%3D10%2Frss.xml%3FpartnerId%3D2003%26TD_PARAM%3Dhttp%253A%252F%252Fclkuk.tradedoubler.com %252Fclick%253Fp%253D23708%2526a%253D1515427%2526url%253D)

That simplepie demo just has general formatting. But your right, simplepie can be complex to learn how to use all the features, its incredibly flexable and there is a learning curve that goes with it. I'm useless with code, so i'm only able to use and adapt code that someone else has written. We are both doing something similar, but each case is different in its own way. I'm also trying to work within a Joomla website framework, this is very difficult for me as i don't understand how it works.

I will follow any further developments in your thread with interest!

John.

LJackson
01-04-2009, 08:25 PM
We are much alike :D

i've only been learning php for 3 or 4 months and my coding knowledge is limited, and like yourself i can adapt code to suit my needs but as for doing it all my self apart from the basics im useless:) but like all things its a learning curb.

ive herd of joomla but ive never used or looked into it but i will one day :)

that itunes feed was used/setup when i was trying to get simplepie to work but as i was unable to do it i gave up with it :)

i too will keep an eye on your thread for further developments.
best of luck with it all
Luke

LJackson
01-06-2009, 01:15 PM
ok guys i have a slight problem, i used to get a notice which only apeared once in a while, and usualy disappeared after hitting refresh. but since i have added the following code to my page

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting (E_ALL);?>

the notice appears all the time.
it is:

Notice: Undefined offset: 1 in /customers/kernow-connect.com/kernow-connect.com/httpd.www/entertainment.php on line 306


and line 306 is

list ($used_link, $no) = split ('\"', $used_temp);

any ideas why i am getting this notice.

this is the entire feed code:

// Get XML
$xml=simplexml_load_file("http://www.amazon.co.uk/rss/bestsellers/videogames?tag=kernconn-21");

// How many items to display from the RSS Feed ...
$count = 1;

foreach ($xml->channel->item as $item) {
$link = trim($item->link);
$link = $link."?ie=UTF8&tag=kernconn-21";
// Parse-out the photo for each item ...
$photosource = get_string_between($item->description, '<img src="','"');

// If you don't want the # of the item to appear,
// Use a modified title ... $short_title
list ($no, $short_title) = split (':', $item->title);

// Parse-out the platform for each item ...
$platform = get_string_between($short_title, '(',')');
$reviewsource = get_string_between($item->description, 'Customer Review: <','width');
$buynew = get_string_between($item->description, '"#990000">','</b>');
$buynewlink = get_string_between($item->description, '<a href="','">');
$buynewlink = trim($buynewlink);
$buynewlink = $buynewlink."?ie=UTF8&tag=kernconn-21";

$used_temp =get_string_between($item->description, '</font> <br /><a href="','used & new');

list ($used_link, $no) = split ('\"', $used_temp);
$used_link = trim($used_link);
$used_link = $used_link."?ie=UTF8&tag=kernconn-21";

$costs = get_string_between($item->description, 'Buy new:</a>','</font>');
$old_price = get_string_between($costs, '<strike>','</strike>');
if ($old_price == ''){
$old_price = "N/A";
}
else {
$old_price = "<s>$old_price</s>";
}
$buynew_price = get_string_between($costs, '<b>','</b>');
$used_price = get_string_between($item->description, '<span class="price">','</span>');

list ($no, $short_title) = split (': ', $item->title);

if($count > 0){


echo"
<div class='recommendsTitle'><a href='$link'>$short_title</a></div>
<div class='recommendsImage'><a href='$link'><img src='$photosource' alt='$short_title' width='100' height='100' border='0' /></a></div>

<div class='recommendsContainer_yellow'>
<div class='feedItems_main'><b>Platform</b><br />$platform</div>
<div class='feedItems_main'><b>Average Review</b><br /><$reviewsource></div></div>

<div class='recommendsContainer_pink'>
<div class='feedItems_sub'><b><a href='$buynewlink'>Buy New</b></a><br />$buynew_price</div>
<div class='feedItems_sub'><b>Was</b><br /><s>$old_price</s></div>
<div class='feedItems_sub'><a href='$used_link'><b>Used and New</b></a> from $used_price</div></div>

";

}
$count--;
}


cheers
Luke

hinch
01-06-2009, 04:49 PM
the split isn't giving the list() 2 elements to work with.

try

list ($used_link, $no) = split ('"', $used_temp);

OR

$used_link = $used_temp[0];

Since $used_temp is an array and the link is the first element in the array you can simply call that element directly instead of arsing around with lists especially since you don't use the $no var anyway

LJackson
01-07-2009, 12:12 AM
thanks mate got that working :)

i have another irritating problem,

scenario:
i have 1 store which is to be shown in two categories this is the only store so i have set its category to EntCom and i have created a query on the entertainment page as such:

$sql = "SELECT * FROM stores WHERE ( category = 'Entertainment' OR category = 'EntComp' ) ORDER BY rating DESC";

so that it includes this store with the entertainment stores and i did a similar thing on the electronics page

$sql = "SELECT * FROM stores WHERE ( category = 'Electronics' OR category = 'EntComp' ) ORDER BY rating DESC";


which works a treat, i now have 1 store entry instead of two seperate stores of the same store in my database.

the trouble this creates is that if the user click on the entertainment page and subsequently the stores page i want it to show a feed which relates to the entertainment category.
and if the user clicks the electronics page and then the stores page it shows the feed related to the electronics page.
(still following? :D)

so i was thinking of sending some data via the get command and have it attached to the web address in the same way that the stores data is already sent.

so i already have

$idReference = "?sID=".$storeName;
$linkHTML = "<a href = \"stores.php".$idReference."\">";
$linkHTMLEnd = "</a>";


on the entertainment page to send the store name to my web address so that the stores page can display the correct info for that store.

and the store page is:

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$idReference = '';

if (isset($_GET['sID'])) {
$idReference = $_GET['sID'];
}
}

which is used in my querys to get the correct info which matches $idReference.
(still with me?)

so i thought i could just set up something similar by adding the following to the entertainment page.

$category = "ent";
$idReference = "?sID=".$storeName;
$cat = "?Cat=".$category;
$linkHTML = "<a href = \"stores.php".$idReference.$cat."\">";
$linkHTMLEnd = "</a>";


and on the stores page

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$idReference = '';
$cat = '';

if (isset($_GET['sID'])) {
$idReference = $_GET['sID'];
}
if (isset($_GET['Cat'])) {
$cat = $_GET['Cat'];
}
}

which included the ?Cat=ent at the end of my url

then for my store which is listed in two categories where i set it up to display the feed url i added this

if ($cat == "Ent"){
$xml=simplexml_load_file("http://www.amazon.co.uk/rss/bestsellers/videogames?tag=kernconn-21");
}
else {
$xml=simplexml_load_file("http://www.amazon.co.uk/rss/bestsellers/electronics?tag=kernconn-21");
}

which i thought was sweet until i ran the website and nothing displayes for any of the stores :(

which i was gutted about.

any ideas why this isnt working???

sorry for going on and on and on but i was trying to paint a picture for you :)

cheers
Luke

hinch
01-07-2009, 10:48 AM
$cat = "?Cat=".$category;

should be

$cat = "&Cat=".$category; as its being chained after a ? already so its a 2nd get var

LJackson
01-07-2009, 02:34 PM
cheers mate thats now working fine :D

hinch
01-07-2009, 02:57 PM
nps easy mistake :)

ps: i charge a % of your profits :)

LJackson
01-07-2009, 05:26 PM
nps easy mistake :)

ps: i charge a % of your profits :)

lol, when ive earnt millions i'll remember you :D

LJackson
01-09-2009, 02:06 PM
right i have what i think a tricky problem, after contacting the majority of stores on my site a lot of them wont provide me with a specific product feed to meet my needs :(

so......

my next great idea is to have several text files storing the product title or id if present of the top 10 items/offers/releases and then some how add to an array? and do some code to look up each of the product info that relates to the name/id from the stores main feed.

make sence?

for example text file currys.txt to contain something like
LX232NDS
KSE334FR
KI878EEW
KU38FHF8
DHGWT36
FJ83MD83
OOE32WW
LK373838
GG763473
HY737373

and the have my code read this file and have it some how look up the stores product feed which may contain 10000 products to match each of the ten product ids and pull out the specific info on each?

would this be possible?
cheers
Luke

hinch
01-09-2009, 02:38 PM
not 100% sure I get you but here's my guess.

reading in the file and creating your list array isn't a big issue so i'll leave you to do to that.

now make a copy of your display page that displays all 10k products. in site its while/for loop that loops through each major card in the xml feed you do another loop/check someting along the lines of

if ($item->itemid is inarray($productarray)) {
echo out the product as usual;
}

that way it'll cycle through your entire 10k products but only display it if it matches against an element in the array. i'm not too sure on the function for array element searching in php but should be easy enough for you to look it up to work out the actual functions behind the logic I've mentioned above.

LJackson
01-09-2009, 03:10 PM
ok thanks for that but remember your talking to a spanner when it comes to this mombo jumbo :D.

at the moment i have just set up an array in the php file

$itemList = array("Radio 1 Live Lounge: Volume 2: 2cd","Jungle Book: 2dvd: Hmv Exclusive: Special Edition","Spirit");

and the nodes in this feed are set up as
- <products>
- <product>
<productname>

so the code i currently have to check if the product is included within my array is what you provided me with

$xml=simplexml_load_file("http://www.amazon.co.uk/rss/new-releases/electronics?tag=kernconn-21");


// How many items to display from the RSS Feed ...
$count = 1;

$itemList = array("Radio 1 Live Lounge: Volume 2: 2cd","Jungle Book: 2dvd: Hmv Exclusive: Special Edition","Spirit");
foreach ($xml->product as $item){


if ($item->product is inarray($itemlist)) {








echo"
<div class='recommends'>
<a href='{$item->deeplink}'>{$item->productname}</a><br />
<a href='{$item->deeplink}'><img src='{$item->imageURL}' alt='{$item->productname}' width='100' height='100' border='0' vspace='10' /></a><br />

</div>
";

}
$count--;
}
}


but its returning an error

Parse error: syntax error, unexpected T_STRING in C:\wamp\www\affiliate\test.php on line 40


which is this line

if ($item->product is inarray($itemlist)) {

the inarray doesnt seem to change colour to say that it is valid?

have you got any ideas
cheers mate

edit
===

ok i have found out the inarray should be in_array() good old w3schools :)

here is my new code which isnt showing any errors but its also not displaying anything:(

// Get XML
$xml=simplexml_load_file("http://www.amazon.co.uk/rss/new-releases/electronics?tag=kernconn-21");


// How many items to display from the RSS Feed ...
$count = 1;

$itemList = array("Radio 1 Live Lounge: Volume 2: 2cd","Jungle Book: 2dvd: Hmv Exclusive: Special Edition","Spirit");
foreach ($xml->products as $item){


if (in_array($item->product,$itemList)){








echo"
<div class='recommends'>
<a href='{$item->deeplink}'>{$item->productname}</a><br />
<a href='{$item->deeplink}'><img src='{$item->imageURL}' alt='{$item->productname}' width='100' height='100' border='0' vspace='10' /></a><br />

</div>
";

}
$count--;
}

mlseim
01-09-2009, 03:29 PM
Luke ...
How are you going to maintain that list of 10 items?
Is that list going to need to be changed very often?

Sounds like an admin problem ... and you should be looking
for some other automatic way of doing it. But I don't know
what that would be. (maybe you're breaking some new ground here).

LJackson
01-09-2009, 03:36 PM
Hi mlseim,

the list of ten items i will have to update manually, most of the stores provide a list of the top items in an email, but for some reason are unwilling to provide a specific feed.

i will probabily be updated once a week i should imagine.

this is the only solution i can think of to get the specific items i want :)

i think if we achieved this then its safe to say that we (mostly you two) have covered nearly every angle possible :)

hinch
01-09-2009, 04:08 PM
hrmp you could store in a db table for each feed ie

s_FeedURL,s_Items

and that way you can store your array as just a csv list in s_Items

then you could do if (in_array($item->product,$DB_Retrieved_list)){ }

would save you having to manually update loads of files as you could create a simple db admin page for you to update them etc.

as to why if (in_array($item->product,$itemList)){ isn't working/displaying anything i'm not entirely sure just make sure that your $item->product variable its spitting out does actually match at least one value in your array. also may be worth while adding an } else {
echo "no match found";
}
onto that if as well just whilst you debug stuff. that way you can check if your if statement is actually catching anything or if its not matching at all and thats why its not displaying anything.

hinch
01-09-2009, 04:15 PM
right i've just ran up a small test locally using this code



$itemList = array("Radio 1 Live Lounge: Volume 2: 2cd","Jungle Book: 2dvd: Hmv Exclusive: Special Edition","Spirit");
$prodtofind = "Spirit";
if (in_array($prodtofind,$itemList)){
echo "found product";
} else {
echo "no product found";
}


it works fine so I'm assuming its an issue with your $item->product either not returning something in your list or your list variable doesn't match the exact content of $item->product.

Unsure if its case sensitive either though so you may want to strtolower() both your array and your $item->product to rule out case matching issues.

LJackson
01-09-2009, 04:18 PM
@Hinch,

not sure if i understand or not, ut what your saying is to have the top items stored in a database table and call that table,

and have a page on my site which i can log in to and can update the items and update the tables that way?

(said you were talking to a spanner :D )

cheers
Luke

hinch
01-09-2009, 04:21 PM
yeah luke that'd be the easiest way for you to maintain your lists. saves you having to edit lots of text files and upload them onto the server also means you could allow someone else to manage the site in future should it prove a success :)

mlseim
01-09-2009, 04:23 PM
When they send you the emails, are they text emails or HTML emails?

It would be interesting if the emails were sent to some Yahoo email address
and then a PHP script (pop3) grabbed them and processed the data (a CRON job).
Probably a lot of work, but the idea is interesting.

In any event ...
If the stores are able to generate an email and send it out, seems like they could
just as easily generate an XML file too.

hinch
01-09-2009, 04:30 PM
retrieving emails from a pop3 server using php is fairly simple strangely enough the complex part is if the subject changes ensuring that it picks the correct email out each month.

i'm also assuming that he's using shared hosts so crons are big nono's

he could perhaps do an xml transform on the raw feed vs his list of "top10" or whatever but thats drifting way out of my league in php.

LJackson
01-09-2009, 04:31 PM
When they send you the emails, are they text emails or HTML emails?

It would be interesting if the emails were sent to some Yahoo email address
and then a PHP script (pop3) grabbed them and processed the data (a CRON job).
Probably a lot of work, but the idea is interesting.

In any event ...
If the stores are able to generate an email and send it out, seems like they could
just as easily generate an XML file too.

you'd have thought so but for some reason they wont,

the emails will probably be a mix some will send html and other will send text i expect :)

LJackson
01-09-2009, 04:31 PM
yeah luke that'd be the easiest way for you to maintain your lists. saves you having to edit lots of text files and upload them onto the server also means you could allow someone else to manage the site in future should it prove a success :)

cool that sounds easy enough :)

LJackson
01-09-2009, 04:48 PM
ok ive managed to get it working :D
using:


// Get XML
$xml=simplexml_load_file("http://www.kernow-connect.com/feeds/hmvtop10.xml");


// How many items to display from the RSS Feed ...
$count = 1;

$itemList = array("Radio 1 Live Lounge: Volume 2: 2cd","Jungle Book: 2dvd: Hmv Exclusive: Special Edition","Spirit");
foreach ($xml->product as $item){
echo "$item->productname<br />";

if (in_array($item->productname,$itemList)){

echo"
<div class='recommends'>
<a href='{$item->deepLink}'>{$item->productname}</a><br />
<a href='{$item->deepLink}'><img src='{$item->imageURL}' alt='{$item->productname}' width='100' height='100' border='0' vspace='10' /></a><br />

</div>";

}
$count--;
}


sorry hinch didnt see your example above, ive managed to print out all the titles and match the ones in the array and print of the relivant info :D

now im gonna setup a table within my database to store the top10 items, should i have all the items in one record e.g
store id=>1 top10=>item1;item2;item3; etc etc
or should i have it so that it is
store id =>1 top10=>item1
store id=>1 top10=>item2

would it be easy to get the individual values using the first example?

cheers

hinch
01-09-2009, 04:57 PM
i'd go down the route of storing your match list all in one column and your feed url in another so you can do something like



// Get XML
$feedurl = "http://www.kernow-connect.com/feeds/hmvtop10.xml";
$xml=simplexml_load_file($feedurl);
$selectsql = "select * from table where feedurl=$feedurl";
$sql_run = mysql_query($sql) or die(mysql_error());
$itemList = mysql_fetch_row($sql_run);

// How many items to display from the RSS Feed ...
$count = 1;

foreach ($xml->product as $item){
echo "$item->productname<br />";

if (in_array($item->productname,$itemList)){

echo"
<div class='recommends'>
<a href='{$item->deepLink}'>{$item->productname}</a><br />
<a href='{$item->deepLink}'><img src='{$item->imageURL}' alt='{$item->productname}' width='100' height='100' border='0' vspace='10' /></a><br />

</div>";

}
$count--;
}



That way you don't have to change your in_array code and its just automated based on what feedurl your using and it pulls out the correct array based on the feedurl (just make sure the feedurls you use in the db column match the feed urls you set in code.

also would be an idea to make an ID column in the database autonumber primary key you'll use your ID for specifying which record to edit/delete within your admin interface.

try this for your table setup.

CREATE TABLE `DBNAME`.`tblfeeds` (
`ID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`s_FeedURL` VARCHAR( 500 ) NULL ,
`s_itemList` VARCHAR( 5000 ) NULL ,
PRIMARY KEY ( `ID` )
) ENGINE = InnoDB

hinch
01-09-2009, 04:59 PM
you'll notice in my above example you don't need to grab the individual elements of your itemlist column as they're stored as a CSV unsure if you'd need to save them as
"item1","item2" etc or just
item1,item2 etc

you'll have to test and try them out

LJackson
01-09-2009, 05:25 PM
cool thanks for that i will start the table process now :)

LJackson
01-09-2009, 07:05 PM
ok i have set up the table, fortunatly i already had one set up which i needed to modify,

i have 3 rows for each store
1 = top10
1= top offers
1=newest releases

example of top10
rssID, store, description, s_FeedURL, s_itemList.

i tried it out for virgin with the list they provided me a while back
s_FeedURL = http://mysite.com/feeds/virgin.xml
s_itemList = "Deluxe Makeover";"Harness Sphereing for Two";"Super Car Thrill";"Relaxation Day for Two";"Aston Martin";"Introductory Flying Lessons";"Classic Lunch Cruise and London Eye";"Theatre and Dinner for Two";"Full Day Paintballing for Two";"Silverstone Thrill"

and i used the code

// Get XML
$feedurl = "http://www.kernow-connect.com/feeds/virgin.xml";
$xml=simplexml_load_file($feedurl);
$selectsql = "select s_itemList from rss_feeds where description = 'top' and s_feedurl=$feedurl";
$sql_run = mysql_query($sql) or die(mysql_error());
$itemList = mysql_fetch_row($sql_run);

// How many items to display from the RSS Feed ...
//$count = 10;

foreach ($xml->products as $item){
echo "$item->productname<br />";

if (in_array($item->name,$itemList)){

echo"
<div class='recommends'>
<a href='{$item->purl}'>{$item->name}</a><br />
<a href='{$item->purl}'><img src='{$item->awImage}' alt='{$item->name}' width='100' height='100' border='0' vspace='10' /></a><br />

</div>";

}
//$count--;
}


but when i run it i get Query was empty
not sure why tho

any ideas.
Luke

LJackson
01-09-2009, 07:13 PM
i think its my foreach bit that wrong,

i dont think i have the correct feed info.

this (http://www.kernow-connect.com/feeds/virgin.xml)is the feed

when i try and print $item->name nothing appears, but the feed looks more complicated than the others?

can you have a look at the feed please to see if i have got the right info :)

many thanks
Luke

edit
===

ok i have changed the code to

// Get XML
$feedurl="http://www.kernow-connect.com/feeds/virgin.xml";
$xml=simplexml_load_file($feedurl);
$selectsql = "select * from rss_feeds where description = 'top' and s_feedurl=$feedurl";
$sql_run = mysql_query($selectsql) or die(mysql_error());
$itemList = mysql_fetch_row($sql_run);

// How many items to display from the RSS Feed ...
//$count = 10;

foreach ($xml->products as $item){
echo "$item->name<br />";

if (in_array($item->name,$itemList)){

echo"
<div class='recommends'>
<a href='{$item->purl}'>{$item->name}</a><br />
<a href='{$item->purl}'><img src='{$item->awImage}' alt='{$item->name}' width='100' height='100' border='0' vspace='10' /></a><br />

</div>";

}
//$count--;
}


and uploaded it to my host i have also included the database info above this code and i am getting an error saying
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '://www.kernow-connect.com/feeds/virgin.xml' at line 1

any ideas what this means
cheers

hinch
01-09-2009, 07:37 PM
put single quotes around $feedurl

s_feedurl='$feedurl'

as its a string your doing a comparison against.

also remember that column names are case sensitive. so is it s_FeedURL in the db or s_feedurl

finally don't forget your array will be pulled out wrong as you've used semi colons in the db to separate the values so yuo'll want to implode on ; to convert it to a proper array using ,

LJackson
01-09-2009, 08:09 PM
wow so many silly errors in one simple job :)

ok i am not getting a blank screen which i suppose is a step forward, still thing my feed info is wrong

foreach ($xml->products as $item){

if (in_array($item->name,$itemList)){

ot sure tho i will double check all my info in the database

edit
===
checked database all data looks ok, tried echoing out all the items within the feed but no success by removing the if in_array statment but it still returned nothing so its gotta be the feed info i am using

any ideas
Cheers

hinch
01-09-2009, 09:48 PM
try it on a feed that you know works and displays correctly

what i'd do is take your listings page that displays correctly the entire contents of a feed.
then step by step add in the rest of the stuff at each stage checking it works and still displays the contents.

the inarray check needs to be within your for loop so it can check each element of your feed as it loops through the feed to see if it matches.

you have to make sure $itemList is in the format item1,item2,item3 though for it to work.

LJackson
01-10-2009, 11:41 PM
Hi guys,

ok ive tried this out on a feed which i know works and i get nothing display

i have printed out the array
and it came up with

Array ( [0] => "it","Harry Potter & The Order Of The Phoenix: 2dvd" )

which im guessing is correct or should it be one item per array 'slot' with 9 slots in total?

any ways its not displayng anything? which may be because its looking for a match to "it, Harry Potter & The Order Of The Phoenix: 2dvd" with in the feed which isnt there not sure tho???

any ideas
cheers
Luke

edit
----

yeah that is the problem

i used the same feed etc but created my own array using exactly the same items like

$itemList = array("It","Harry Potter & The Order Of The Phoenix: 2dvd");

and when i printed out the array i got
Array ( [0] => It [1] => Harry Potter & The Order Of The Phoenix: 2dvd )

which is how i thought it should have been

and the items printed out with all the info

so i just need to figure out how to get the array to print out like this from my database info???

hinch
01-11-2009, 12:57 PM
as i said you need to explode the contents in the db :)

so if in your db you have

"it","harry pothead"

when you retrieve if from the db just doing

$itemList = $dbvalue[0];

Will give you $itemList as a string not an array if you do

$itemList = explode(",",$dbvalue[0]);

though it'll split your string on a , and convert it to an array for you so you can then use it as you were before

LJackson
01-11-2009, 03:53 PM
cool thanks mate seems to be working :D

the second part of that expression
explode(",",$dbvalue[0]);

does that stipulate the start of the array?

cheers
Luke

hinch
01-11-2009, 05:53 PM
that stipulates the column number within a db table assuming you've done a select *

so if you have


$selectsql = "select * from rss_feeds where description = 'top' and s_feedurl=$feedurl";
$sql_run = mysql_query($selectsql) or die(mysql_error());
$dbvalue = mysql_fetch_row($sql_run);


and the table rss_feeds has 5 columns and the column your interested in is column number 5 then you'd use


explode(",",$dbvalue[4]);

this is because mysql effectively returns an array for each row it selects where each element of that array is a table column.

you can also reference the column name if you like ie: $dbvalue['s_FeedURL'] i believe I just prefer using column count references instead.
Remember like any array the start value is 0 (zero) not 1 so in our example above column 5 is return element 4

LJackson
01-11-2009, 06:06 PM
cheers mate.

just need to get it working with the other feed here (http://www.kernow-connect.com/feeds/virgin.xml)

i will be playing with this tonight :D
cheers

LJackson
01-11-2009, 08:42 PM
ok i have tried what i think would work but it hasnt :(


if ($db_found) {


// Get XML
$feedurl="http://www.kernow-connect.com/feeds/virgin.xml";
$xml=simplexml_load_file($feedurl);
$selectsql = "select s_itemList from rss_feeds where description = 'top' and s_FeedURL='$feedurl'";
$sql_run = mysql_query($selectsql) or die(mysql_error());
$itemList = mysql_fetch_row($sql_run);
$itemList = explode(",",$itemList[0]);//[0] determins the collumn number
//$itemList2 = array("It","Harry Potter & The Order Of The Phoenix: 2dvd");
print_r ($itemList);
//print_r ($itemList2);

// How many items to display from the RSS Feed ...
//$count = 10;

foreach ($xml->products as $item){
//echo "$item->productname<br />";

if (in_array($item->name,$itemList)){

echo"
<div class='recommends'>
<a href='{$item->awLink}'>{$item->name}</a><br />
<a href='{$item->awLink}'><img src='{$item->mImage}' alt='{$item->name}' height='100' border='0' vspace='10' /></a><br />

</div>";

}
//$count--;
}
}

i think
foreach ($xml->products as $item){
is wrong but im not sure what it should be

any ideas guys? :)

cheers
Luke

hinch
01-12-2009, 12:26 AM
does it work without the db code in there to display the entire feed contents?

does echo "$item->productname<br />"; display the product name your after ?

is $item->name right? or should it be $item->productname ?

LJackson
01-12-2009, 10:13 AM
Hi mate,

no it doesnt work at all :(
i tried it without the database stuff and no joy,

$item->name is correct i think but because the feed is a different to the others i think i need to do something else before this part.

the feeds structure is
- <products>
- <merch mId>
- <prod awId>
<pId></pId>
<name>

so i tried foreach ($xml->prod awId as $item){

but it through up a t string error
not sure how to get around it?

cheers

hinch
01-12-2009, 10:35 AM
$xml->'prod awId' perhaps ?

i'm not too familiar with class handling of spaced variables

LJackson
01-12-2009, 11:07 AM
unfortunatly nope it returns
T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE

bloody thing lol

wheres mlseim with his bag of tricks :D

cheers

mlseim
01-12-2009, 03:28 PM
I sort of am lost on what the latest discussion has been.

I think this is the feed ?
http://www.kernow-connect.com/feeds/virgin.xml

And what is the code you have so far, and what is not working?

LJackson
01-12-2009, 03:40 PM
you mean you havent been following :p lol

yeah that is the correct feed :thumbsup:

this is the code in which i have to display the feed contents as with the early feeds

// Get XML
$feedurl="http://www.kernow-connect.com/feeds/virgin.xml";
$xml=simplexml_load_file($feedurl);
$selectsql = "select s_itemList from rss_feeds where description = 'top' and s_FeedURL='$feedurl'";
$sql_run = mysql_query($selectsql) or die(mysql_error());
$itemList = mysql_fetch_row($sql_run);
$itemList = explode(",",$itemList[0]);//[0] determins the collumn number
//$itemList2 = array("It","Harry Potter & The Order Of The Phoenix: 2dvd");
print_r ($itemList);
//print_r ($itemList2);

// How many items to display from the RSS Feed ...
//$count = 10;

foreach ($xml->prod awId as $item){
echo "$item->name<br />";

if (in_array($item->name,$itemList)){

echo"
<div class='recommends'>
<a href='{$item->awLink}'>{$item->name}</a><br />
<a href='{$item->awLink}'><img src='{$item->mImage}' alt='{$item->name}' height='100' border='0' vspace='10' /></a><br />

</div>";

}
//$count--;
}
}


this code pulls out the item if its stored in the database but i cant even get all the items to display,

i think its got something to do with the

foreach ($xml->prod awId as $item){

it doesnt like the prod awId ( im not even sure if that right or not)

any ideas
cheers mate

mlseim
01-12-2009, 05:37 PM
I got it to display ... but didn't do any MySQL stuff.

This might get you closer though ...


<?php

// Get XML
$feedurl="http://www.kernow-connect.com/feeds/virgin.xml";

$xml=simplexml_load_file($feedurl);
//$selectsql = "select s_itemList from rss_feeds where description = 'top' and s_FeedURL='$feedurl'";
//$sql_run = mysql_query($selectsql) or die(mysql_error());
//$itemList = mysql_fetch_row($sql_run);
//$itemList = explode(",",$itemList[0]);//[0] determins the collumn number
//$itemList2 = array("It","Harry Potter & The Order Of The Phoenix: 2dvd");
//print_r ($itemList);
//print_r ($itemList2);

// How many items to display from the RSS Feed ...
$count = 10;

foreach ($xml->merch->prod as $item){
if($count > 0){
echo"
<div class='recommends'>
{$item->name}<br />
<a href='{$item->awLink}'>{$item->name}</a><br />
<a href='{$item->awLink}'><img src='{$item->mImage}' alt='{$item->name}' height='100' border='0' vspace='10' /></a><br />
</div>
";
}
$count--;
}

?>

LJackson
01-12-2009, 06:16 PM
mlseim thank you!!!

its working with the database stuff, many many thanks for that.

with this code

// Get XML
$feedurl="http://www.kernow-connect.com/feeds/physioroom.xml";
$xml=simplexml_load_file($feedurl);
$selectsql = "select s_itemList from rss_feeds where description = 'top' and s_FeedURL='$feedurl'";
$sql_run = mysql_query($selectsql) or die(mysql_error());
$itemList = mysql_fetch_row($sql_run);
$itemList = explode(",",$itemList[0]);//[0] determins the column number
print_r ($itemList);
//print_r ($itemList2);

// How many items to display from the RSS Feed ...
//$count = 10;

foreach ($xml->merch->prod as $item){
//echo "$item->name<br />";

if (in_array($item->name,$itemList)){

echo"
<div class='recommends'>
<a href='{$item->awLink}'>{$item->name}</a><br />
<a href='{$item->awLink}'><img src='{$item->mImage}' alt='{$item->name}' height='100' border='0' vspace='10' /></a><br />

</div>";

}
//$count--;
}
}

it prints out the items in no particular order, is there a way to print it out in the order it is stored in the array? just so that if im given the top 10 in order and it printed out as 1 last and ten first for example the data is wrong.

any ideas
cheers

mlseim
01-12-2009, 06:51 PM
Is there any way to know what the correct order is?
Example, they have some sort of numbering?

I'm thinking of putting items into an array, sorting it, then reprinting the array in order.
But to sort, there must be some type of numbering thing (or a date) or something to sort.

LJackson
01-12-2009, 06:54 PM
no there isnt but i see no reason why i cant add a number to them in the databse record :)

cheers

mlseim
01-12-2009, 08:14 PM
Well then how will you know if they are in order or not in order?
How do you know they are out of order now?

LJackson
01-12-2009, 08:35 PM
because in the db for example
they come out as

Array ( [0] => Humax HD freesat+ PVR ( Humax freesat+ PVR ) [1] => Ion 35mm Film Scanner ( Ion Deluxe Film Scan ) [2] => minibook™ Ultra-Portable Laptop ( 7inch Mini Laptop ) etc etc

but when its printing out the info it pulls them out in the order in which they appear in the feed so in array [2] is feed item 1 it will be pulled out first, if you see what i mean not sure why tho

LJackson
01-12-2009, 11:10 PM
saying that, it will be more difficult than 1st thought :(

because the

if (in_array($item->name,$itemList)){

is checking the value in the database to that in the feed and only displays the info if it matches,

therefor if i put a 1,2 etc infront of the values in the database it would never match the values in the feed.

so i would need to do more coding to work around that, so i think its best to leave it until it becomes really necessary

cheers

hinch
01-13-2009, 12:03 AM
you'd have to narrow down to your 10 items instead of displaying them load them each into an array.

then array sort your array into the order you want them then display them :)

if you store in your db a 3d array where each element of your list of items wanted also has an element with your display order.

then when you create your array of products carry across your display order per actual item as read from the feed then array sort on the display order with it being a 3d array it'll sort your product elements into the correct order.

hope this makes sense i'm very very tired atm struggling with the english

LJackson
01-13-2009, 02:07 PM
Hi hinch, yeah i understand what your saying mate, its something i will look into once it becomes necessary, at the moment im not to bothered by it :)

1 thing i need some help with is.

when displaying out the description node in the feed i am getting html code display e.g

Official&nbsp;2008-09&nbsp;AC Milan&nbsp;home&nbsp;shirt. Authentic&nbsp;short Sleeve&nbsp;Adidas

how do i display the contents without the html in it?

this is how im accessing the data

<div class='test1'>{$item->desc}</div><br />

cheers

hinch
01-13-2009, 04:31 PM
something like html_entity_decode()

http://uk3.php.net/manual/en/function.html-entity-decode.php

LJackson
01-13-2009, 06:21 PM
that looks like the thing im after thanks,

will have a go at the tomorrow :)

LJackson
01-13-2009, 06:46 PM
why wait till tomorrow :D

it works just as i want, thank you

hinch
01-13-2009, 08:57 PM
nps we'll teach you php yet don't worry :)

LJackson
01-14-2009, 07:16 AM
lol cheers mate, i REALLY appreciate it

LJackson
01-14-2009, 02:26 PM
ok before, we got all the values from the database and created an array with them

$itemList = mysql_fetch_row($sql_run);
$itemList = explode(",",$itemList[0]);//[0] determins the column number

my next question is how do i get just the first item/string?

i asume i keep the above code but then i need another line to get the first one only?

cheers Mate

LJackson
01-14-2009, 02:53 PM
i tried

list($item1,$item2,$item3,$item4,$item5,$item6,$item7,$item8,$item9,$item10) = explode(",",$itemList[0]);



if (in_array($item1,$itemList)){

but this through up many warnings and didnt work :(

hinch
01-14-2009, 03:49 PM
$itemList = explode(",",$itemList[0]);//[0] determins the column number

$itemList[0];

will be the first item in your array exactly the same as when you split your mysql returned array.

so to make it a little clearer

$mysqlArr= mysql_fetch_row($sql_run);
$itemList = explode(",",$mysqlArr[0]);//[0] determins the column number
$item1 = $itemList[0];

LJackson
01-14-2009, 04:20 PM
thats what i first thought but it didnt work, like at the mo i am getting all the items display, but it might be that my code needs tweeking, i had a similar prob on another test i was doing but i got that working by tweeking :)

i will update you on that if i still cant fix it :)

in the db the info is seperated by , does it have to be a , or can it be anything because one of my feeds has a title which includes ,'s i was wondering if i could seperate the items with a # for example?

cheers
Mate

p.s $test = $itemList[0] the correct value but still listing all items?
which is what the list array was doing

hinch
01-14-2009, 04:31 PM
you can seperate them using anything you like just remember to update your explode to use that symbol in turn i tend to use ^ as it never appears in human language usually

you may have to implode or re-explode the $itemList variable after the mysql explode for it to register it as an array properly not entirely sure without running up a test but I haven't had chance to look at that yet

LJackson
01-14-2009, 04:39 PM
cool...

the array thing is kinda working it gets the correct value but it doesnt just display that 1 it displays all?

need to tinker with my code and it should work :)

cheers

hinch
01-14-2009, 10:13 PM
its probably classing it as a string not an array if its showing the entire data set instead of just element [0]

try exploding it again. let me know if your still having issues with this tomorrow and i'll see if I can run up the code to just spit out the first element of the db retrieved string for you.

LJackson
01-14-2009, 11:28 PM
will do cheers mate

LJackson
01-15-2009, 04:15 PM
Hi mate, still unable to solve this :(

so far i have

$rss_feed = "SELECT s_FeedURL FROM rss_feeds WHERE store = '$storeName' AND description ='top'";
$rss_result = mysql_query($rss_feed);
$rss_row = mysql_fetch_array($rss_result);
$rssIndividual[$i] = $rss_row['s_FeedURL'];


which retrieves the feed url


$selectsql = "select s_itemList from rss_feeds where description = 'top' and s_FeedURL='$rssIndividual[$i]'";
$sql_run = mysql_query($selectsql) or die(mysql_error());
$mysqlArr = mysql_fetch_row($sql_run);
$itemList = explode("^",$mysqlArr[0]);//[0] determins the column number
$item1[$i] = $itemList[0];


pulls out the first item which it does as when printing $item1[$i] later on it returns the correct value

then for my top 3 stores i have


for ($i = 0; $i < 3; $i++) {
print "<div class='recommends'>";
print "$item1[$i]";



if ($rssIndividual[$i] == ''){
print "Sorry No Information Currently Available";
}

elseif ($feedID[$i] == '1'){

$feedurl = $rssIndividual[$i];
$xml=simplexml_load_file($feedurl);



foreach ($xml->merch->prod as $item){
if (in_array($item1[$i],$itemList)){
print {$item->name};
$test = html_entity_decode($item->desc);


}
}
}


print "</div>";


which as i say gets the correct value but doesnt display the item, it prints every item title where as it should print the first one

i removed the following because it was causing the page to load very slow and ever item was displayed

<div class='itemcont'>
<div class='itemheader'><a href='{$item->awLink}'>{$item->name}</a></div><br />
<div class='itemimg'><a href='{$item->awLink}'><img src='{$item->mImage}' alt='{$item->name}' height='100' border='0' vspace='0' /></a></div>
<div class='itemdesc'>$test</div><br />
<div class='itemprice'>Buy Now For {$item->price->search}</div>
<div class='iteminfo'><a href='{$item->awLink}'>More Info</a></div>
</div>";


any ideas mate
cheers
Luke

LJackson
01-15-2009, 10:46 PM
ok i have some how managed to print out just item1 by adding a count

elseif ($feedID[$i] == '1'){

$feedurl = $rssIndividual[$i];
$xml=simplexml_load_file($feedurl);
$count = 1;


foreach ($xml->merch->prod as $item){
$desc = html_entity_decode($item->desc);
if (in_array($item->name,$test[$i])){

if($count > 0){
echo"
<div class='itemcont'>
<div class='itemheader'><a href='{$item->awLink}'>{$item->name}</a></div><br />
<div class='itemimg'><a href='{$item->awLink}'><img src='{$item->mImage}' alt='{$item->name}' height='100' border='0' vspace='0' /></a></div>
<div class='itemdesc'>$desc</div><br />
<div class='itemprice'>Buy Now For {$item->price->search}</div>
<div class='iteminfo'><a href='{$item->awLink}'>More Info</a></div>
</div>";




$count--;
}
}
}
}

which works :D

how do i convert odd symbols in the $item->desc to utf8 char set ive already converted the html chars using

$desc = html_entity_decode($item->desc);

now i need to get rid of any odd characters :)

cheers

hinch
01-16-2009, 11:40 AM
define odd characters.

LJackson
01-16-2009, 01:07 PM
odd characters = a box instead of a pound sign which i have had before but it was solved by adding

mysql_query("SET NAMES 'utf8'"); to my page, but as this new problem is not stored in the database but in the feed itself the above code doesnt solve it.

cheers

hinch
01-16-2009, 02:19 PM
could try a series of str replace's.

best bet would be to make a function


function funkyCharReplace($inputstring) {
$output = str_replace(whatever,$inputstring);
$output = str_replace(whatever,$output);
$output = str_replace(whatever,$output);
$output = str_replace(whatever,$output);

return $output;
}

Then where you want to sanitize your code just call sometihng like


echo funkyCharReplace($item->name);

for example

its abit manual but since you have no control over the source feeds and what chars they're putting in its the only way I can think of doing it there may be better ways though hopefully someone with more clue than me will come give you an idea.

LJackson
01-16-2009, 02:34 PM
ok cheers mate that gives me an idea :) mmay post a new thread to see what others suggest :)

cheers again!!!!!

LJackson
02-01-2009, 08:59 PM
Hi all hope your all well,

i have spent the last couple of weeks gathering info for my site and its nearly at the stage where i have all the info i need.

i am also thinking of sorting out a few things that i want to achieve.

1/ display the items of the feed in the order of the item list.
2/ create a page where i can edit the top items without having to goto myadmin and do it there.

so for point one. the trouble i have is that for some reason when searching for the items in the list, it doesnt look for the first one and pull that out and then goto the second items etc it looks through the entire feed and pulls out the first item that matches the feed so its pulling the items out in the order they appear in the feed not the list. :(

this is the code


$selectsql = "select s_itemList from rss_feeds where description = 'top' and s_FeedURL='$rssIndividual[$i]'";
$sql_run = mysql_query($selectsql) or die(mysql_error());
$mysqlArr = mysql_fetch_row($sql_run);
$itemList = explode("^",$mysqlArr[0]);//[0] determins the column number
$test[$i] = $itemList;

displaying the items

foreach ($xml->merch->prod as $item){
$desc = html_entity_decode($item->desc);
if (in_array($item->pId,$test[$i])){

if($count > 0){
echo"
<div class='indtopitemimg'><img src='http://www.kernow-connect.com/images/top.jpg'></div>
<div class='inditemheader'><a href='{$item->awLink}'>{$item->name}</a></div><br />
<div class='inditemimg'><a href='{$item->awLink}'><img src='{$item->mImage}' alt='{$item->name}' height='100' border='0' vspace='0' /></a></div>
<div class='inditemdesc'>$desc</div><br />
<div class='inditemprice'>Buy Now For {$item->price->search}</div>
<div class='inditeminfo'><a href='{$item->awLink}'>More Info</a></div>";

$count--;
}
}

when i tried to solve this i did

for ($i = 0; $i < $rows; $i++) {

$selectsql = "select s_itemList from rss_feeds where description = 'top' and s_FeedURL='http://www.kernow-connect.com/feeds/virgin.xml'";
$sql_run = mysql_query($selectsql) or die(mysql_error());
$mysqlArr = mysql_fetch_row($sql_run);
$itemList = explode("^",$mysqlArr[0]);//[0] determins the column number
$itemList[$i] = $itemList;
print_r ($itemList);
print "<br />";

for ($i = 0; $i < 10; $i++) {
print $itemList[$i];
print "<br />";

}}

which prints out the itemlist items in the correct order so i thried to modify it to work with my feed


for ($i = 0; $i < $rows; $i++) {

$selectsql = "select s_itemList from rss_feeds where description = 'top' and s_FeedURL='http://www.kernow-connect.com/feeds/virgin.xml'";
$sql_run = mysql_query($selectsql) or die(mysql_error());
$mysqlArr = mysql_fetch_row($sql_run);
$itemList = explode("^",$mysqlArr[0]);//[0] determins the column number
$itemList[$i] = $itemList;
print_r ($itemList);
print "<br />";

for ($i = 0; $i < 10; $i++) {
print $itemList[$i];
print "<br />";

$xml=simplexml_load_file('http://www.kernow-connect.com/feeds/virgin.xml');
$count = 1;

foreach ($xml->merch->prod as $item){
$desc = html_entity_decode($item->desc);
if (in_array($item->pId,$itemList[$i])){
print "{$item->pId}";
}
}
}
}

which was causing the following warning

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /customers/kernow-connect.com/kernow-connect.com/httpd.www/entertainmentnew.php on line 118

as for part 2.

im not sure where to start,

i was thinking of having a listbox with all the stores in it and 10 textboxes on the page which change depending on which store is selected can you point me in the correct direction on how to get the textbox to grab the correct data from the database.

cheers
Luke

LJackson
02-16-2009, 07:11 PM
Hi Guys,

I Have quite a major problem, firstly i havent changed any of my code of downloaded any new feeds but i am getting some errors all of a sudden, it seems to be the xml files that contain large amounts of data.

here are some errors im getting


Warning: simplexml_load_file() [function.simplexml-load-file]: (null)(null)http://www.kernow-connect.com/feeds/feed_4586.xml:248417: parser error : out of memory error in /customers/kernow-connect.com/kernow-connect.com/httpd.www/misc.php on line 268

Warning: simplexml_load_file() [function.simplexml-load-file]: </fields> in /customers/kernow-connect.com/kernow-connect.com/httpd.www/misc.php on line 268

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /customers/kernow-connect.com/kernow-connect.com/httpd.www/misc.php on line 268

Warning: simplexml_load_file() [function.simplexml-load-file]: (null)http://www.kernow-connect.com/feeds/feed_4586.xml:248418: parser error : Extra content at the end of the document in /customers/kernow-connect.com/kernow-connect.com/httpd.www/misc.php on line 268

Warning: simplexml_load_file() [function.simplexml-load-file]: </product> in /customers/kernow-connect.com/kernow-connect.com/httpd.www/misc.php on line 268

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /customers/kernow-connect.com/kernow-connect.com/httpd.www/misc.php on line 268

Notice: Trying to get property of non-object in /customers/kernow-connect.com/kernow-connect.com/httpd.www/misc.php on line 271

Warning: Invalid argument supplied for foreach() in /customers/kernow-connect.com/kernow-connect.com/httpd.www/misc.php on line 271

here (http://www.kernow-connect.com/misc.php)is the page

anyone have any ideas as to why i am getting these all of a sudden, its occuring on about 5 feeds?

cheers
Luke

LJackson
02-25-2009, 01:22 PM
it seems to be effecting the large feeds only, not sure why tho
any ideas?

Luke

mlseim
02-25-2009, 02:03 PM
Looks like you are exceeding the memory.
I think the first error is the "exceeding memory".
All of the next errors are a result of the first error (the program has already failed).

Not sure what to do about that.
Maybe you can do some things with your php config file (on the server).
You might have to contact the webhost about that (if you are using a webhost).

LJackson
02-25-2009, 02:25 PM
ah ok :)

yeah im using one.com

its strange why its only just started to happen, didnt used to. i'll contact them see if they can help.

when you say exceeding the memory which memory are you talking about?

cheers mate
Luke

hinch
02-25-2009, 03:29 PM
i'm assuming they've changed the php memory limit as
http://www.kernow-connect.com/stores.php?Cat=ent&sID=Jamster
is throwing a 500 error not even displaying the errors you're listing above.

if possible ask them to increase the php memory limit they'll most likely have it down on something like 10mb between pulling in a 1-2 mb feed then parsing it your probably reaching the cap.

LJackson
02-25-2009, 03:41 PM
hi hinch, if you hit refresh it will display the errors :)

i will contact them now see what they say.

cheers
Luke

LJackson
02-25-2009, 04:11 PM
ok just been chatting to one.com and unfortunatly my php memory is at its limit of 24mb and cant be increases any more :( the guy suggested deleting some of the feeds which i may do and hope that solves it :)

cheers guys

LJackson
03-12-2009, 04:54 PM
hi all,

ok im having a problem with one of my feeds, it looks like the company have changed the feed type from atom to 1.0 or at least i think they have :(

they've done something because my code doesnt work anymore :(

here (http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/sf=143444/limit=10/explicit=true/xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D)is the feed

and here is the code which "was" working :)


// Get XML
$xml=simplexml_load_file("http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/sf=143444/limit=10/explicit=true/xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D");

// How many items to display from the RSS Feed ...
$count = 1;

foreach ($xml->channel->item as $item) {
// Grabbing the NameSpace URI for "itms" and "content" ...
$ns_itms = $item->children('http://phobos.apple.com/rss/1.0/modules/itms/');
$ns_content = $item->children('http://purl.org/rss/1.0/modules/content/');

// Trick the URL to grab the larger size image ...
$photo=str_replace("53x53-50","100x100-75",$ns_itms->coverArt);

// Parse-out the number of songs on an album ...
$songs = get_string_between($ns_content, "<B>Total Songs:</B>","</font>");

//GET SHORT TITLE BY REMOVING THE NUMBER
list ($no, $short_title) = split ('\.', $item->title);

if($count > 0){
echo"
<div class='inditemheader'><a href='{$ns_itms->songLink}'>$short_title</a></div>
<div class='inditemimg'><a href='{$item->link}'><img src='$photo' alt='{$ns_itms->artist} - {$ns_itms->album}' border='0'/></a></div>
<div class='recommendsContainer_yellow'>
<div class='feedItems_main'><b>The Album:</b><br />
<a href='{$item->link}'>{$ns_itms->album}</a></div>

<div class='feedItems_main'><b>Artist:</b><br />
<a href='{$ns_itms->artistLink}'>{$ns_itms->artist}</a></div></div>

<div class='recommendsContainer_pink'>
<div class='feedItems_sub'><b>Total Songs:</b><br />$songs</div>

<div class='feedItems_sub'><b>Genre:</b><br />{$item->category}</div>
<div class='feedItems_sub'><b>Price:</b><br />{$ns_itms->albumPrice}</div></div>";
}
$count--;
}
}

ive tried to get something to show but didnt get anywhere :(

i wish these companies would leave the feeds alone :)

any help would be great
thanks
Luke

mlseim
03-13-2009, 02:25 PM
I can't view their XML behind my firewall ...

So, make sure these Namespace URL's haven't changed:

// Grabbing the NameSpace URI for "itms" and "content" ...
$ns_itms = $item->children('http://phobos.apple.com/rss/1.0/modules/itms/');
$ns_content = $item->children('http://purl.org/rss/1.0/modules/content/');

LJackson
03-13-2009, 03:03 PM
Hi mate,

this is the only two pieces of code i can see which look like they may be what im looking for?

<feed xmlns:im="http://phobos.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<id>http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/sf=143444/limit=10/explicit=true/xml?partnerId=2003&amp;TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26 url%3D</id><title>iTunes Store: Top Songs</title>

here is a piece of code for one of the items within the feed:

<?xml version="1.0" encoding="utf-8"?>

<feed xmlns:im="http://phobos.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<id>http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/sf=143444/limit=10/explicit=true/xml?partnerId=2003&amp;TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26 url%3D</id><title>iTunes Store: Top Songs</title><updated>2009-03-12T08:40:20-07:00</updated><link rel="alternate" type="text/html" href="http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewTop% 3Fid%3D25106%26popId%3D1%26partnerId%3D2003"/><link rel="self" href="http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/sf=143444/limit=10/explicit=true/xml?partnerId=2003&amp;TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26 url%3D"/><icon>http://phobos.apple.com/favicon.ico</icon><author><name>iTunes Store</name><uri>http://www.apple.com/uk/itunes/</uri></author><rights>Copyright 2008 Apple Inc.</rights>

<entry>
<updated>2009-03-12T08:40:20-07:00</updated>


<id>http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D304572809%26id%3D304572794%26s%3D143444%26partnerId%3D2003</id>

<title>Right Round (feat. Ke$ha) - Flo Rida</title>



<im:name>Right Round (feat. Ke$ha)</im:name>

<link rel="alternate" type="text/html" href="http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D304572809%26id%3D304572794%26s%3D143444%26partnerId%3D2003"/>

<im:contentType term="Music" label="Music"><im:contentType term="Track" label="Track"/></im:contentType>

<category term="Hip Hop/Rap" scheme="http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewGenr e%3Fid%3D18%26partnerId%3D2003"/>


<link title="Preview" rel="enclosure" type="audio/x-m4p" href="http://a488.phobos.apple.com/us/r1000/018/Music/0d/62/37/mzi.bmvqlhhq.aac.p.m4p" im:assetType="preview"><im:duration>30000</im:duration></link>

<im:artist href="http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewArti st%3Fid%3D255303209%26partnerId%3D2003">Flo Rida</im:artist>

<im:price amount="0.79000" currency="GBP">0.79</im:price>

<im:image height="30">http://a1.phobos.apple.com/us/r1000/041/Music/58/dc/92/mzi.fqftdfaj.30x30-50.jpg</im:image>

<im:image height="60">http://a1.phobos.apple.com/us/r1000/041/Music/58/dc/92/mzi.fqftdfaj.60x60-50.jpg</im:image>

<im:image height="170">http://a1.phobos.apple.com/us/r1000/041/Music/58/dc/92/mzi.fqftdfaj.170x170-75.jpg</im:image>


<rights>2009 Atlantic Recording Corporation for the United States and WEA International Inc. for the world outside of the United States.</rights>

<im:releaseDate label="09 February 2009">2009-02-09T00:00:00-07:00</im:releaseDate>

<im:collection><im:name>Right Round (feat. Ke$ha) - Single</im:name><link rel="alternate" type="text/html" href="http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fid%3D304572794%26s%3D143444%26partnerId%3D2003"/><im:contentType term="Music" label="Music"><im:contentType term="Album" label="Album"/></im:contentType></im:collection>


<content type="html">&lt;table border=&quot;0&quot; width=&quot;100%&quot;&gt;
&lt;tr&gt;

&lt;td&gt;
&lt;table border=&quot;0&quot; width=&quot;100%&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tr valign=&quot;top&quot; align=&quot;left&quot;&gt;


&lt;td align=&quot;center&quot; width=&quot;166&quot; valign=&quot;top&quot;&gt;
&lt;a href=&quot;http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D304572809%26id%3D304572794%26s%3D143444%26partnerId%3D2003&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://a1.phobos.apple.com/us/r1000/041/Music/58/dc/92/mzi.fqftdfaj.100x100-75.jpg&quot;&gt;&lt;/a&gt;

&lt;/td&gt;
&lt;td width=&quot;10&quot;&gt;&lt;img alt=&quot;&quot; width=&quot;10&quot; height=&quot;1&quot; src=&quot;http://ax.itunes.apple.com/images/spacer.gif&quot;&gt;&lt;/td&gt;

&lt;td width=&quot;95%&quot;&gt;


&lt;b&gt;&lt;a href=&quot;http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D304572809%26id%3D304572794%26s%3D143444%26partnerId%3D2003&quot;&gt;Right Round (feat. Ke$ha)&lt;/a&gt;&lt;/b&gt;&lt;br/&gt;


&lt;a href=&quot;http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fid%3D304572794%26s%3D143444%26partnerId%3D2003&quot;&gt;Right Round (feat. Ke$ha) - Single&lt;/a&gt;&lt;br/&gt;




&lt;a href=&quot;http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewArti st%3Fid%3D255303209%26partnerId%3D2003&quot;&gt;Flo Rida&lt;/a&gt;&lt;br/&gt;


&lt;font size=&quot;2&quot; face=&quot;Helvetica,Arial,Geneva,Swiss,SunSans-Regular&quot;&gt;

&lt;br/&gt;

&lt;b&gt;Genre:&lt;/b&gt; &lt;a href=&quot;http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewGenr e%3Fid%3D18%26partnerId%3D2003&quot;&gt;Hip Hop/Rap&lt;/a&gt;

&lt;br/&gt;
&lt;b&gt;Album Price:&lt;/b&gt; 0.79

&lt;br/&gt;

&lt;b&gt;Release Date:&lt;/b&gt; 09 February 2009

&lt;/font&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;



&lt;font size=&quot;2&quot; face=&quot;Helvetica,Arial,Geneva,Swiss,SunSans-Regular&quot;&gt; &amp;#169; 2009 Atlantic Recording Corporation for the United States and WEA International Inc. for the world outside of the United States.&lt;/font&gt;


&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</content>


hope this helps :)
thanks not sure where i'd be with out you :)
cheers

LJackson
03-14-2009, 06:53 PM
any ideas guys? i cant seem to get it to work :(
cheers

LJackson
03-14-2009, 08:11 PM
p.s how easy would it be to create a feed, (product) what i was thinking was to have a feed set up which included the best offer/item from each of the stores on my site for use on the category pages only this would be very useful, but im not sure how to go about it? would getting image urls shouldnt be a problem should it?

would i just need to have a basic setup
<offers>
<top_offer>
<storeid>game</storeid>
<title>too human xbox</title>
<desc>xbox game</desc>
<price>24.99</price>
<link>dah de dah</link>
<image>image url here</image
</top_offer>
....
......
</offers>

something like that?
cheers
Luke

LJackson
03-16-2009, 07:16 PM
could i create a feed in notepad for example and would i need to add a line at the beginning to say that its a feed?

cheers

p.s i still cant get that itunes feed to work :(

LJackson
03-17-2009, 02:44 PM
hi,

ok i have managed to get some info from the itunes feed
here (http://www.kernow-connect.com/itunestest.php)is what i have

and here (http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/sf=143444/limit=10/explicit=true/xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D)is the feed

and here is the source file for one song

<entry>
<updated>2009-03-17T05:49:34-07:00</updated>


<id>http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D304572809%26id%3D304572794%26s%3D143444%26partnerId%3D2003</id>

<title>Right Round (feat. Ke$ha) - Flo Rida</title>



<im:name>Right Round (feat. Ke$ha)</im:name>

<link rel="alternate" type="text/html" href="http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D304572809%26id%3D304572794%26s%3D143444%26partnerId%3D2003"/>

<im:contentType term="Music" label="Music"><im:contentType term="Track" label="Track"/></im:contentType>

<category term="Hip Hop/Rap" scheme="http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewGenr e%3Fid%3D18%26partnerId%3D2003"/>


<link title="Preview" rel="enclosure" type="audio/x-m4p" href="http://a488.phobos.apple.com/us/r1000/018/Music/0d/62/37/mzi.bmvqlhhq.aac.p.m4p" im:assetType="preview"><im:duration>30000</im:duration></link>

<im:artist href="http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewArti st%3Fid%3D255303209%26partnerId%3D2003">Flo Rida</im:artist>

<im:price amount="0.79000" currency="GBP">0.79</im:price>

<im:image height="30">http://a1.phobos.apple.com/us/r1000/041/Music/58/dc/92/mzi.fqftdfaj.30x30-50.jpg</im:image>

<im:image height="60">http://a1.phobos.apple.com/us/r1000/041/Music/58/dc/92/mzi.fqftdfaj.60x60-50.jpg</im:image>

<im:image height="170">http://a1.phobos.apple.com/us/r1000/041/Music/58/dc/92/mzi.fqftdfaj.170x170-75.jpg</im:image>


<rights>2009 Atlantic Recording Corporation for the United States and WEA International Inc. for the world outside of the United States.</rights>

<im:releaseDate label="09 February 2009">2009-02-09T00:00:00-07:00</im:releaseDate>

<im:collection><im:name>Right Round (feat. Ke$ha) - Single</im:name><link rel="alternate" type="text/html" href="http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fid%3D304572794%26s%3D143444%26partnerId%3D2003"/><im:contentType term="Music" label="Music"><im:contentType term="Album" label="Album"/></im:contentType></im:collection>


<content type="html">&lt;table border=&quot;0&quot; width=&quot;100%&quot;&gt;
&lt;tr&gt;

&lt;td&gt;
&lt;table border=&quot;0&quot; width=&quot;100%&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tr valign=&quot;top&quot; align=&quot;left&quot;&gt;


&lt;td align=&quot;center&quot; width=&quot;166&quot; valign=&quot;top&quot;&gt;
&lt;a href=&quot;http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D304572809%26id%3D304572794%26s%3D143444%26partnerId%3D2003&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://a1.phobos.apple.com/us/r1000/041/Music/58/dc/92/mzi.fqftdfaj.100x100-75.jpg&quot;&gt;&lt;/a&gt;

&lt;/td&gt;
&lt;td width=&quot;10&quot;&gt;&lt;img alt=&quot;&quot; width=&quot;10&quot; height=&quot;1&quot; src=&quot;http://ax.itunes.apple.com/images/spacer.gif&quot;&gt;&lt;/td&gt;

&lt;td width=&quot;95%&quot;&gt;


&lt;b&gt;&lt;a href=&quot;http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fi%3D304572809%26id%3D304572794%26s%3D143444%26partnerId%3D2003&quot;&gt;Right Round (feat. Ke$ha)&lt;/a&gt;&lt;/b&gt;&lt;br/&gt;


&lt;a href=&quot;http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbu m%3Fid%3D304572794%26s%3D143444%26partnerId%3D2003&quot;&gt;Right Round (feat. Ke$ha) - Single&lt;/a&gt;&lt;br/&gt;




&lt;a href=&quot;http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewArti st%3Fid%3D255303209%26partnerId%3D2003&quot;&gt;Flo Rida&lt;/a&gt;&lt;br/&gt;


&lt;font size=&quot;2&quot; face=&quot;Helvetica,Arial,Geneva,Swiss,SunSans-Regular&quot;&gt;

&lt;br/&gt;

&lt;b&gt;Genre:&lt;/b&gt; &lt;a href=&quot;http://clkuk.tradedoubler.com/click?p=23708&amp;a=1515427&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewGenr e%3Fid%3D18%26partnerId%3D2003&quot;&gt;Hip Hop/Rap&lt;/a&gt;

&lt;br/&gt;
&lt;b&gt;Album Price:&lt;/b&gt; 0.79

&lt;br/&gt;

&lt;b&gt;Release Date:&lt;/b&gt; 09 February 2009

&lt;/font&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;



&lt;font size=&quot;2&quot; face=&quot;Helvetica,Arial,Geneva,Swiss,SunSans-Regular&quot;&gt; &amp;#169; 2009 Atlantic Recording Corporation for the United States and WEA International Inc. for the world outside of the United States.&lt;/font&gt;


&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</content>

</entry>

what i need out of this is
the album name
the large image
the genre
the release date label vaue
and the links to work :)

here is my code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

$xml=simplexml_load_file("http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/sf=143444/limit=10/explicit=true/xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D");



// How many items to display from the RSS Feed ...
$count = 10;

foreach ($xml->entry as $item) {
// Grabbing the NameSpace URI for "itms" and "content" ...
$ns_itms = $item->children('http://phobos.apple.com/rss');
$ns_content = $item->children('http://www.w3.org/2005/Atom');

// Parse-out the number of songs on an album ...
$genre = get_string_between($item->content, "Genre:","&lt;br/&gt;");

if($count > 0){
echo"
<div class='inditemheader'><a href='{$item->link}'>{$item->title}</a></div>
<div class='inditemimg'><a href='{$item->link}'><img src='{$ns_itms->image}' alt='{$ns_itms->artist} - {$ns_itms->album}' border='0'/></a></div>
<div class='recommendsContainer_yellow'>
<div class='feedItems_main'><b>The Album:</b>
<href='{$ns_itms->collection->link}'>{$ns_itms->collection->name}</a></div>

<div class='feedItems_main'><b>Artist:</b>
{$ns_itms->artist}</div></div>

<div class='recommendsContainer_pink'>
<div class='feedItems_sub'><b>Release Date:</b>{$ns_itms->releaseDate}</div>

<div class='feedItems_sub'><b>Genre:</b>$genre</div>
<div class='feedItems_sub'><b>Price:</b>{$ns_itms->price}</div></div><p>";
}
$count--;
}

?>
</body>
</html>


if you can help with this i'd appreciate it :)
thanks
Luke

LJackson
03-18-2009, 04:58 PM
ok i have managed to get my own feed working :) but im still stuck on the itunes feed :( any ideas

cheers
Luke

LJackson
03-23-2009, 05:34 PM
right i have managed to get enough out of the itunes feed for what i want but im having trouble with another feed and getting the id out of it as the itself is wrapped in quotes

here is the feed

his XML file does not appear to have any style information associated with it. The document tree is shown below.


<merchantProductFeed>

<merchant id="1418">

<prod id="9936669">

<text>
<name>Peter Jackson&#39;s King Kong</name>

<promo>
PLAY.com - FREE DELIVERY ON EVERYTHING! 1+ Million products! inc. CDs DVDs Games Books Electronics Mobiles Gadgets Clothing Computer upgrades Memorabilia Calendars Posters Bargains and more. In-stock products dispatched within 24 hours. Safe and secure transactions. Award winning customer service.
</promo>
</text>

<uri>

<awTrack>
http://www.awin1.com/pclick.php?p=9936669&a=79524&m=1418
</awTrack>

<awImage>
http://images.productserve.com/preview/1418/9936669.jpg
</awImage>
</uri>

<price>
<buynow>5.00</buynow>
</price>
<cat/>
<brand/>
</prod>

and here is what ive got so far

foreach ($xml->merchant->prod as $item){
echo"
{$item->id}<br />
<a href='{$item->uri->awTrack}'>{$item->text->name}</a><br />";
}

the name and links work but as my php pull out the ids which are stored in my database and without being able to get the ids from this feed i cant pull out the items stored in the db.

any ideas how i can pull them out?

cheers
Luke

wbdvlpr
03-24-2009, 10:29 AM
I just stumbled upon this page of conversation .. not sure if you have tried something like
http://simplepie.org/

http://simplepie.org/wiki/setup/sample_page

good luck.
Dj

LJackson
03-24-2009, 11:09 AM
Hi mate,

yeah i have tried simplepie and was told to use php's simplexml_load_file function which after using is a lot easier than simplepie :)

thanks for your reply mate
appreciate it :)

its ok i have sorted this problem now thanks
Luke



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum