...

View Full Version : Import from wordpress



M.W.S.
02-25-2008, 01: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:

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

M.W.S.
02-25-2008, 03: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"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.0/"
>
<channel>
<item>
<title>The title</title>
<link>http://example.com/10</link>
<pubDate>Thu, 12 Apr 2007 14:52:12 +0000</pubDate>
<dc:creator>M.W.S.</dc:creator>
<category><![CDATA[Windows]]></category>
<guid isPermaLink="false">http://tutorials.ge/?p=10</guid>
<description></description>
<content:encoded><![CDATA[Some content here]]></content:encoded>
</item>
</channel>
</rss>

mlseim
02-25-2008, 10: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):
http://www.catpin.com/robots2_net.php

Here's the PHP script using CURL:


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

# INITIATE CURL.
$curl = curl_init();

# CURL SETTINGS.
curl_setopt($curl, CURLOPT_URL,"$feed_url");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

# GRAB THE XML FILE.
$xmlTwitter = curl_exec($curl);

curl_close($curl);

# SET UP XML OBJECT.
# 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;
}
else{
$newstring = substr($item->description, 0, $char);
}
if($count > 0){
//in case they have non-closed italics or bold, etc ...
echo"</i></b></u></a>\n";
echo"
<div style='font-family:arial; font-size:.8em;'>
<b>{$item->title}</b><br />
$newstring ... <a href='{$item->guid}'>read more</a>
<br /><br />
</div>
";
}
$count--;
}
?>



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.

M.W.S.
02-26-2008, 01:34 PM
Thank you, very much, you helped me a great deal :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum