I'm trying to get a RSS feed from Sotheby's website working on my site using a standard PHP reader function that uses simplexml_load_file and a loop but it doesn't work properly. When I plug in this code I get a 'Failed loading XML Start tag expected, '<' not found' error.'
<?php
$url = 'http://apps.shareholder.com/rss/rss.aspx?channels=2908&companyid=BID&sh_auth=1184301877%2E0%2E0%2E42356%2E14434fd9e3fcb0c832c884fe9ff36e31';
libxml_use_internal_errors(true);
$sxe = simplexml_load_string($url);
if ($sxe === false) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
print_r($rss);
?>
I've tried using curl from this posting but it just prints an empty pre tag.
Here's the reader PHP code I was using...
<?php
$url = "http://apps.shareholder.com/rss/rss.aspx?channels=2908&companyid=BID&sh_auth=1184301877%2E0%2E0%2E42356%2E14434fd9e3fcb0c832c884fe9ff36e31";
$rss = simplexml_load_file($url);
if($rss)
{
$items = $rss->channel->item;
foreach($items as $item)
{
if($i==5) break;
$title = $item->title;
$link = $item->link;
$published_on = $item->pubDate;
$description = $item->description;?>
<hr>
<div class="news-story">
<?php
echo '<h3><a href="'.$link.'">'.$title.'</a></h3>';
echo '<span class="news-date">('.$published_on.')</span>';
?>
</div>
<?php
$i++;
}
}
?>
And here is the Sotheby's news RSS feed I was trying to pull from.
Any help or suggestions would be very helpful. Thanks!
EDIT
Thanks The fourth bird for referring to this Stack question, it worked last night, but when I check today it stopped working...
<?php
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$url = 'http://apps.shareholder.com/rss/rss.aspx?channels=2908&companyid=BID&sh_auth=1184301877%2E0%2E0%2E42356%2E14434fd9e3fcb0c832c884fe9ff36e31';
$xml = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xml);
print_r($xml);
?>
These are some of the errors I'm getting in my MAMP php_error.log:
[18-Dec-2015 07:46:41 America/New_York] PHP Warning: simplexml_load_string(): </html> in (*my site root folder)
[18-Dec-2015 07:46:41 America/New_York] PHP Warning: simplexml_load_string(): ^ in (*my site root folder)
[18-Dec-2015 07:46:41 America/New_York] PHP Warning: simplexml_load_string(): Entity: line 85: parser error : Premature end of data in tag html line 2 in (*my site root folder)
And they basically repeat.
In the first code block you provided, you are using simplexml_load_string.
The manual describes the first parameter as:
A well-formed XML string
In you code you are passing a url. If you want to use simplexml_load_string
, the answer to this question might help you:
Using SimpleXML to load remote URL
In the second code block you provided, you use simplexml_load_file
The manual describes the first parameter as:
Path to the XML file
If I try the code in the second code block it is showing me the data from RSS Feed, it only gives me this PHP Notice:
PHP Notice: Undefined variable: i