/    Sign up×
Community /Pin to ProfileBookmark

Need help with PHP and XML to TXT

I need to write a PHP script that when run reads in an XML RSS feed like this: [url]http://www.usatoday.com/repurposing/OffbeatRss.xml[/url] and writes out just the text to a simple text file.

I’m pretty green at PHP, any tips on how to start or snippets would be greatly appreciated!

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsJan 17.2006 — your example uses xml and xsl
Copy linkTweet thisAlerts:
@TrajectoauthorJan 17.2006 — How about something like this:

http://my.abcnews.go.com/rsspublic/world_rss20.xml

I need to read everything in as a string and parse out everything between the "< >" then write out a text file.
Copy linkTweet thisAlerts:
@HuevoosJan 17.2006 — I don't quite understand what you want, but look at this link, if this is what you'r looking for I can post the messy source code

http://www.esbasura.com/rss.php?rss=abcnews

(there is a little prob with the links with <!CDATA but is easy to get through)
Copy linkTweet thisAlerts:
@TrajectoauthorJan 17.2006 — It would just be a dump of the contents as a text file. So it wouldn't even be an HTML page, just a "news.txt" file.
Copy linkTweet thisAlerts:
@HuevoosJan 17.2006 — well the code for that is
[code=php]
$ch = curl_init("http://my.abcnews.go.com/rsspublic/world_rss20.xml");
$fp = fopen("escroto.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
[/code]


assuming you have the curl library
Copy linkTweet thisAlerts:
@TrajectoauthorJan 17.2006 — That looks like what I want! I need to remove the "< >" brackets and everything between them though.

Is this where you get curl at?: http://curl.haxx.se/
Copy linkTweet thisAlerts:
@Markbad311Jan 17.2006 — can someone define the Curl Library I am a newbie and trying tio pick up on anything my book hasn't taught me.
Copy linkTweet thisAlerts:
@HuevoosJan 17.2006 — Yep that's where you get the curl library

I don't know if strip_tags() will work with xml Why don't you give it a try.

Markbad: http://php.net/curl
×

Success!

Help @Trajecto 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...