Main Menu
collapse

Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

User Info

Welcome Guest.
Please log in.

Who's Online

  • Dot Guests: 882
  • Dot Hidden: 0
  • Dot Users: 1
  • Dot Users Online:

Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]


NEED HELP? If you're looking for support with Simple Portal, look no further than the Support Board!

Need help with XML fetching/decryption/displaying

Started by ccbtimewiz, August 03, 2012, 05:19:21 PM

Previous topic - Next topic

0 Members and 4 Guests are viewing this topic.

ccbtimewiz

Okay, so here's the PHP script I made to fetch the XML of a feed from Twitter:

<?php/*	This script was made with the intention of fetching the Twitter feed of	Nintendo of America (NintendoAmerica), and then cleaning it free of things not needed.*/header('Content-type: application/xml');$feed_url = 'http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=NintendoAmerica';function clean_feed($feed){	$feed = str_replace('<title>NintendoAmerica: ', '<title>', $feed);	return $feed;}echo clean_feed(file_get_contents($feed_url));?>


The problem is... it's not showing anything? I can't find the issue here, can anyone with knowledge with XML maybe point me the right way?  I looked at the source code for the page and it showed the feed, the way it should be, but it's not being displayed properly? Is it an extension problem (like should I use mod_rewrite to create a file.xml or something?

Chen Zhen


Man of many aliases,

Try using cURL to read the desired xml file into a variable.


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=NintendoAmerica");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);


.. then you can explode it to an array of links or whatever you are after.

ccbtimewiz

LOL I don't have THAT many aliases. :P

The feed is already established, I'm just converting it to a string, altering it, then returning it exactly as it would be. I don't need to do anything else with it, though I can look into the curling method to see if I can make something that does it.

ccbtimewiz

Hmm, curling it does return what I want, but so did what I did earlier... the problem is the reader doesn't understand that the file is an RSS feed.

Chen Zhen

Quote from: Colette on August 03, 2012, 08:14:53 PM
Hmm, curling it does return what I want, but so did what I did earlier... the problem is the reader doesn't understand that the file is an RSS feed.

Hmm... You can try the simplexml_load_file command (PHP 5) instead of file_get_contents which interprets the file as an object. Your current method is not fetching all the necessary tag elements (nor did cURL) & therefore there is no <title> tag that it can reference for your string replacement.

ie.

$xml = @simplexml_load_file($feed_url);

$data = false;
foreach ($xml->channel->item as $item)
$data .= $item->title;   

echo $data;



There is also a DOM object method

$dom=new DOMDocument();
$dom->load($feed_url);
$xml = $dom->saveXML();
echo $xml;


.. in which case you can try editing the title tags using DOM.

[SiNaN]

Try changing the header to this:

header('Content-Type: application/rss+xml;');
And slowly, you come to realize... It's all as it should be...