/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Loading an External RSS Feed via simplexml_load_file()

I am having problems loading an [B]external RSS feed[/B] on my site and I am looking for a some assistance. I have successfully loaded an internal RSS feed from my blog, but for some reason, my site can’t display an RSS feed from my Digg account.

I checked my php settings and noticed that [I]allow_url_fopen [/I]is [B]enabled[/B], so I am not sure what else to check.

I’ve searched these forums and I google’d it quite extensively, but I haven’t found a similar case example and resolution. Any help you can provide would be greatly appreciated!

Here’s the code:

[code=php]
// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
// XML Feed

function processFeed($rss,$type) {

# Initiate variables
$_GET[‘newsoutput’] = “”;
$xml = “”;

if(fopen($rss, “r”)) {
$xml = simplexml_load_file($rss);
} else {
echo ‘<p>Could not open file!</p>’;
}

$_GET[‘newsoutput’] = “<ul class=”standard”>”;

switch ($type) {

case “blog”:

foreach ($xml->channel->item as $item) {
for ($i = 0; $i < 2; $i++) {

foreach ($item[$i]->pubDate as $date) {
#$date = str_replace(“+0000”, “”, $date);
$date = substr($date, 0, -15);
$_GET[‘newsoutput’] .= “<li><strong>$date</strong><br />”;
}
foreach ($item[$i]->link as $link) {
$_GET[‘newsoutput’] .= “<a href=”$link”>”;
}
foreach ($item[$i]->title as $title) {
$_GET[‘newsoutput’] .= “$title</a></li>”;
}
}
}
break;
# End case “blog”

case “digg”:

foreach ($xml->channel->item as $item) {
for ($i = 0; $i < 2; $i++) {

foreach ($item[$i]->pubDate as $date) {
$date = substr($date, 0, -15);
$_GET[‘newsoutput’] .= “<li><strong>$date</strong><br />”;
}
foreach ($item[$i]->link as $link) {
$_GET[‘newsoutput’] .= “<a href=”$link”>”;
}
foreach ($item[$i]->title as $title) {
$_GET[‘newsoutput’] .= “$title</a></li>”;
}
}
}
break;
# End case “digg”

} # End Switch

$_GET[‘newsoutput’] .= “</ul>”;
echo $_GET[‘newsoutput’];
}
[/code]

and the initiated function:

[code=php]
processFeed(“http://www.digg.com/users/username/history.rss”,”digg”);
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@abovethefoldauthorNov 19.2007 — anyone have any thoughts regarding this post?
×

Success!

Help @abovethefold spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...