Hi there everyone!
My issue: I'm having a problem finding a way to import current ebay auctions into a website database, so I thought I'd try to scrape the information from an RSS feed of current listings. I subscribed to a third party feed system and learned a bit about simplexml_load_string. I found a function in the comments that was supposed to allow for a more graceful success/failure of the feed load and I tried to plug my info into it.
My feed: http://bayfeeds.com/wheeltasticsales.xml
<?php
function loadXML2($domain, $path, $timeout = 30) {
/*
Usage:
$xml = loadXML2("bayfeeds.com", "/wheeltasticsales.xml");
if($xml) {
// xml doc loaded
} else {
// failed. show friendly error message.
}
*/
$fp = fsockopen($domain, 80, $errno, $errstr, $timeout);
if($fp) {
// make request
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: $domain\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
// get response
$resp = "";
while (!feof($fp)) {
$resp .= fgets($fp, 128);
}
fclose($fp);
// check status is 200
$status_regex = "/HTTP\/1\.\d\s(\d+)/";
if(preg_match($status_regex, $resp, $matches) && $matches[1] == 200) {
// load xml as object
$parts = explode("\r\n\r\n", $resp);
return simplexml_load_string($parts[1]);
}
}
return false;
}
$xml = loadXML2("bayfeeds.com", "/wheeltasticsales.xml");
if($xml) {
// xml doc loaded
print_r($xml);
} else {
// failed. show friendly error message.
echo'XML load failed.';
}
?>
But I got some errors that I don't understand at all:
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found in /home/wheeltastic/public_html/rss.php on line 34
Warning: simplexml_load_string() [function.simplexml-load-string]: 145a in /home/wheeltastic/public_html/rss.php on line 34
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/wheeltastic/public_html/rss.php on line 34
XML load failed.
Line 34:
return simplexml_load_string($parts[1]);
Could someone help me figure out what I'm doing wrong?
Thanks for your time!