Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2008
    Location
    At home :p
    Posts
    39
    Thanks
    7
    Thanked 1 Time in 1 Post

    Post Import from wordpress

    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?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Do you mean RSS Feeds?

  • #3
    New Coder
    Join Date
    Jan 2008
    Location
    At home :p
    Posts
    39
    Thanks
    7
    Thanked 1 Time in 1 Post
    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:
    Code:
    <!-- 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>

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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 Code:
    <?php  
    // rss page for Robots.net -  
    $feed_url "http://robots.net/rss/articles.xml";  

    # INITIATE CURL. 
    $curl curl_init(); 

    # CURL SETTINGS. 
    curl_setopt($curlCURLOPT_URL,"$feed_url"); 
    curl_setopt($curlCURLOPT_RETURNTRANSFER1); 
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT0); 

    # 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->description0$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.
    Last edited by mlseim; 02-25-2008 at 10:02 PM.

  • Users who have thanked mlseim for this post:

    M.W.S. (02-26-2008)

  • #5
    New Coder
    Join Date
    Jan 2008
    Location
    At home :p
    Posts
    39
    Thanks
    7
    Thanked 1 Time in 1 Post
    Thank you, very much, you helped me a great deal


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •