Find » Technology » Tutorials » PHP and XML: What to Do and How to ...

PHP and XML: What to Do and How to Do It

By B. Rock, published Feb 16, 2008
Published Content: 60  Total Views: 63,620  Favorited By: 2 CPs
Embed:  
Rating: 3.0 of 5
PHP is a powerful tool for making your website dynamic. Yet you still need content - and XML is a great tool for incorporating dynamic content into your site.

PHP 5 comes with a great built-in library for working with XML. SimpleXML allows you to easily read XML files and parse them into logical bits of data. No more writing XML parsers - the work has been done for you.

So what can you do with PHP and XML together? And how can you do it?

Write Your Own Feed

Many blogs and CMS platforms automatically create RSS feeds. If you're not using one of these, though, you should look into making your own RSS feed. It's a great way to get your content to the user quickly and consistently - so he or she never forgets to come back.

Creating a feed is an amazingly simple process. You need to scrape together a little information - a list of articles with titles, links, and descriptions. Then you need to format it into special XML tags. Finally, you write a file - and you're done.

If you're unfamiliar with the format of an RSS feed, try taking a look at the RSS 2.0 specification. Then look at some sample feeds. Finally, if you're having trouble, have a read through this tutorial on creating your own custom feed.

Parse Someone Else's Feed

There are tons of social bookmarking sites out there - like Digg, dZone, Furl, and others. I'm sure you've got your favorite.

Chances are that your favorite social bookmarking site publishes a feed of new links broken down by topics. Wouldn't it be cool if you could publish those links - updated in real time - on your site?

Well, you can. All you need to do is use SimpleXML to read the feed, break it down into a few common parts, and then create links based on that information. Every feed has at least some basic information on the articles it contains - including a title and a URL. That's all you need to build a list of "Recent Links from My Social Bookmarking Site."

If you want to see an example, check out this tutorial on syndicating an RSS feed. You can see a live feed from dZone.com on the right hand side of the screen.

Get Cool Information from Your Favorite Sites

XML is used to distribute all kinds of information - not use the latest new links.

Takeaways
  • Using XML and PHP, you can build a custom RSS feed for your site.
  • Social Bookmarking sites publish feeds of new links that you can easily syndicate on your site.
  • Tons of information is available through XML - like Digg stats and WoW character data.
Comments
Type in Your Comments Below - (1000 characters left)
Your name:

Submit your own content on this or any topic. Get started »
Advertisment