/    Sign up×
Community /Pin to ProfileBookmark

how to read page source of rss using php?

i have an rss file on some remote server which i want to read.
when i view the page source through firefox, it displays a well-formatted xml of the feeds (which is the way i want). when i open the rss file using php functions and echo it, it displays all messy stuff.
how do i read the xml (page source of the rss) using php?
thanks!

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiFeb 04.2010 — I would probably use SimpleXML for this (if you want to actually work with the XML. If you just want to grab the source try file_get_contents() first, and if the server has disabled URL wrappers then I would give cURL a try.
Copy linkTweet thisAlerts:
@dev_dauthorFeb 04.2010 — i think file_get_contents() returns the same result as reading the file using fopen(). also i dont have access to the xml. xml is actually the page source of the rss i want to read. so simpleXML is also of no use, until i actually get the xml.
Copy linkTweet thisAlerts:
@MindzaiFeb 04.2010 — i think file_get_contents() returns the same result as reading the file using fopen(). also i dont have access to the xml. xml is actually the page source of the rss i want to read. so simpleXML is also of no use, until i actually get the xml.[/QUOTE]

You use SimpleXML to get the XML. Take a look at the manual page for simplexml-load-file. Also it might be useful if you post what is actually being returned when you use file_get_contents.
Copy linkTweet thisAlerts:
@dev_dauthorFeb 04.2010 — i am trying to get the xml of this:

http://twitter.com/statuses/user_timeline/84965112.rss

file_get_contents returns:

"http://twitter.com/Happynin Twitter updates from Happynin' Games / Happynin. en-us 40 Happynin: We're putting in new textures to improve the looks of the humans - polishing up Fowl Play! Sun, 31 Jan 2010 23:52:55 +0000 http://twitter.com/Happynin/statuses/8471672382 http://twitter.com/Happynin/statuses/8471672382 Happynin: Working hard on Fowl Play - we've put in some terrific music in the game from our composer, really makes you want to poop on people! Fri, 29 Jan 2010 23:34:47 +0000 http://twitter.com/Happynin/statuses/8389008513 http://twitter.com/Happynin/statuses/8389008513 Happynin: RT..."

and what i want is:

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

<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:georss="http://www.georss.org/georss">

<channel>

<title>Twitter / Happynin</title>

<link>http://twitter.com/Happynin</link>

<atom:link type="application/rss+xml" href="http://twitter.com/statuses/user_timeline/84965112.rss" rel="self"/>

<description>Twitter updates from Happynin' Games / Happynin.</description>

<language>en-us</language>

<ttl>40</ttl>

<item>

<title>Happynin: We're putting in new textures to improve the looks of the humans - polishing up Fowl Play!</title>

<description>Happynin: We're putting in new textures to improve the looks of the humans - polishing up Fowl Play!</description>

<pubDate>Sun, 31 Jan 2010 23:52:55 +0000</pubDate>

<guid>http://twitter.com/Happynin/statuses/8471672382</guid>

<link>http://twitter.com/Happynin/statuses/8471672382</link>

</item>

"

How can i get it?
Copy linkTweet thisAlerts:
@MindzaiFeb 04.2010 — And that's what you're getting, but you are not converting the html entities before displaying it.

[code=php]
<?php

$url = 'http://twitter.com/statuses/user_timeline/84965112.rss';
echo htmlentities(file_get_contents($url));

?>
[/code]


As I said though, SimpleXML is the way to go.
Copy linkTweet thisAlerts:
@dev_dauthorFeb 04.2010 — oh, i see!!

thank you!
×

Success!

Help @dev_d 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.19,
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,
)...