View Full Version : Import from wordpress

02-25-2008, 02:25 PM
Hello, I'm building a script and I want to import posts from wordpress. I had been trying to do this myself for a long time, but I couldn't figure it out.
Any ideas? :confused:

02-25-2008, 03:58 PM
Do you mean RSS Feeds?

02-25-2008, 04:09 PM
No, I have a wordpress exported XML file, which contains posts and other stuff. I want to somehow import them and than to put in other database. Well, the main thing is to import it to variables. The xml file looks like this:

<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
<!-- It contains information about your blog's posts, comments, and categories. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your blog. -->

<!-- To import this information into a WordPress blog follow these steps. -->
<!-- 1. Log into that blog as an administrator. -->
<!-- 2. Go to Manage: Import in the blog's admin panels. -->
<!-- 3. Choose "WordPress" from the list. -->
<!-- 4. Upload this file using the form provided on that page. -->
<!-- 5. You will first be asked to map the authors in this export file to users -->
<!-- on the blog. For each author, you may choose to map to an -->
<!-- existing user on the blog or to create a new user -->
<!-- 6. WordPress will then import each of the posts, comments, and categories -->
<!-- contained in this file into your blog -->

<!-- generator="wordpress/2.1.3" created="2007-05-10 16:05"-->
<rss version="2.0"
<title>The title</title>
<pubDate>Thu, 12 Apr 2007 14:52:12 +0000</pubDate>
<guid isPermaLink="false">http://tutorials.ge/?p=10</guid>
<content:encoded><![CDATA[Some content here]]></content:encoded>

02-25-2008, 11:00 PM
OK ... that's pretty much like an RSS reader, instead of displaying the RSS feed
on a website, you save the data into a database.

The next question is whether or not you can use CURL (which is the easiest way).

Below is a simple example of using CURL to read someone's RSS feed and
grab variables (whatever ones you want). The example displays the XML RSS Feed on
a web page, but you could save the data instead of displaying it.

Here's the test page (the output):

Here's the PHP script using CURL:

// rss page for Robots.net -
$feed_url = "http://robots.net/rss/articles.xml";

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL,"$feed_url");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

$xmlTwitter = curl_exec($curl);


# Use one line or the other, depending on version of PHP.
# Comment-out the one you are not using ...
//$xml = new SimpleXMLElement($xmlTwitter);
$xml = simplexml_load_string($xmlTwitter);

// How many items to display
$count = 5;

// How many characters from each item
// 0 (zero) will show them all.
$char = 200;

foreach ($xml->channel->item as $item) {
if($char == 0){
$newstring = $item->description;
$newstring = substr($item->description, 0, $char);
if($count > 0){
//in case they have non-closed italics or bold, etc ...
<div style='font-family:arial; font-size:.8em;'>
<b>{$item->title}</b><br />
$newstring ... <a href='{$item->guid}'>read more</a>
<br /><br />

So you would read your own XML file(s) and grab the various things you need.
Instead of outputting the variables, do whatever you want with them.

If you use PHP5+, you shouldn't have any CURL problems, but with PHP4, you
may not be able to do it this way. You'll have to resort to fopen(), which is
a lot harder to deal with ... and harder to parse-out the variables. Using CURL
pretty much makes it incredibly simple.

02-26-2008, 02:34 PM
Thank you, very much, you helped me a great deal :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum